From 97fc7de6754c8b5c383d7d5e3f9e26b3bbfb08fb Mon Sep 17 00:00:00 2001 From: Anthony Rubick <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Sun, 9 Jul 2023 20:07:09 -0700 Subject: fix: minor code cleanup and pedantic lints (#134) --- src/repl/mod.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/repl/mod.rs') diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 8f3d184..a728e2e 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -55,7 +55,7 @@ impl Repl { Ok(Signal::Success(line)) => { already_ctrlc = false; abort.reset(); - match self.handle_line(handler.clone(), line) { + match self.handle_line(&handler, &line) { Ok(quit) => { if quit { break; @@ -69,12 +69,11 @@ impl Repl { } Ok(Signal::CtrlC) => { abort.set_ctrlc(); - if !already_ctrlc { - already_ctrlc = true; - print_now!("(To exit, press Ctrl+C again or Ctrl+D or type .exit)\n\n"); - } else { + if already_ctrlc { break; } + already_ctrlc = true; + print_now!("(To exit, press Ctrl+C again or Ctrl+D or type .exit)\n\n"); } Ok(Signal::CtrlD) => { abort.set_ctrld(); @@ -86,9 +85,9 @@ impl Repl { Ok(()) } - fn handle_line(&mut self, handler: Arc, line: String) -> Result { - let line = clean_multiline_symbols(&line); - match parse_command(&line) { + fn handle_line(&mut self, handler: &Arc, line: &str) -> Result { + let line = clean_multiline_symbols(line); + match parse_command(line.as_ref()) { Some((cmd, args)) => match cmd { ".exit" => { return Ok(true); @@ -176,7 +175,7 @@ Press Ctrl+C to abort readline, Ctrl+D to exit the REPL fn clean_multiline_symbols(line: &str) -> Cow { let trimed_line = line.trim(); match trimed_line.chars().next() { - Some('{') | Some('[') | Some('(') => trimed_line[1..trimed_line.len() - 1].into(), + Some('{' | '[' | '(') => trimed_line[1..trimed_line.len() - 1].into(), _ => Cow::Borrowed(line), } } -- cgit v1.2.3