diff --git a/Cargo.toml b/Cargo.toml index 30c2d0dd44..8f24200779 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ documentation = "http://phsym.github.io/shrust" readme = "README.md" license = "MIT" keywords = ["shell", "console", "interactive", "terminal", "command"] +edition = "2018" [dependencies] prettytable-rs = "^0.8" diff --git a/examples/data.rs b/examples/data.rs index 74a49b965c..e705430967 100644 --- a/examples/data.rs +++ b/examples/data.rs @@ -6,13 +6,13 @@ fn main() { let v = Vec::new(); let mut shell = Shell::new(v); shell.new_command("push", "Add string to the list", 1, |io, v, s| { - try!(writeln!(io, "Pushing {}", s[0])); + writeln!(io, "Pushing {}", s[0])?; v.push(s[0].to_string()); Ok(()) }); shell.new_command_noargs("list", "List strings", |io, v| { for s in v { - try!(writeln!(io, "{}", s)); + writeln!(io, "{}", s)?; } Ok(()) }); diff --git a/examples/default.rs b/examples/default.rs index 70e256e897..b3e8e132c9 100644 --- a/examples/default.rs +++ b/examples/default.rs @@ -5,7 +5,7 @@ use std::io::prelude::*; fn main() { let mut shell = Shell::new(()); shell.set_default(|io, _, cmd| { - try!(writeln!(io, "Hello from default handler !!! Received: {}", cmd)); + writeln!(io, "Hello from default handler !!! Received: {}", cmd)?; Ok(()) }); shell.run_loop(&mut ShellIO::default()); diff --git a/examples/dummy.rs b/examples/dummy.rs index 8b80fc28b6..eb38dfece9 100644 --- a/examples/dummy.rs +++ b/examples/dummy.rs @@ -5,7 +5,7 @@ use std::io::prelude::*; fn main() { let mut shell = Shell::new(()); shell.new_command_noargs("hello", "Say 'hello' to the world", |io, _| { - try!(writeln!(io, "Hello World !!!")); + writeln!(io, "Hello World !!!")?; Ok(()) }); diff --git a/examples/map.rs b/examples/map.rs index 5686ca6643..248b43ceff 100644 --- a/examples/map.rs +++ b/examples/map.rs @@ -10,18 +10,18 @@ fn main() { let mut shell = Shell::new(map); shell.new_command("put", "Insert a value", 2, |_, map, args| { - map.insert(try!(usize::from_str(args[0])), args[1].to_string()); + map.insert(usize::from_str(args[0])?, args[1].to_string()); Ok(()) }); shell.new_command("get", "Get a value", 1, |io, map, args| { - match map.get(&try!(usize::from_str(args[0]))) { + match map.get(&usize::from_str(args[0])?) { Some(val) => writeln!(io, "{}", val).unwrap(), None => writeln!(io, "Not found").unwrap() }; Ok(()) }); shell.new_command("remove", "Remove a value", 1, |_, map, args| { - map.remove(&try!(usize::from_str(args[0]))); + map.remove(&usize::from_str(args[0])?); Ok(()) }); shell.new_command("list", "List all values", 0, |io, map, _| { diff --git a/examples/socket.rs b/examples/socket.rs index fe94a0db17..3298792e9c 100644 --- a/examples/socket.rs +++ b/examples/socket.rs @@ -16,18 +16,18 @@ fn main() { let mut shell = Shell::new(map); shell.new_command(&"put", &"Insert a value", 2, |_, map, args| { - map.lock().unwrap().insert(try!(usize::from_str(args[0])), args[1].to_string()); + map.lock().unwrap().insert(usize::from_str(args[0])?, args[1].to_string()); Ok(()) }); shell.new_command("get", "Get a value", 1, |io, map, args| { - match map.lock().unwrap().get(&try!(usize::from_str(args[0]))) { + match map.lock().unwrap().get(&usize::from_str(args[0])?) { Some(val) => writeln!(io, "{}", val).unwrap(), None => writeln!(io, "Not found").unwrap() }; Ok(()) }); shell.new_command("remove", "Remove a value", 1, |_, map, args| { - map.lock().unwrap().remove(&try!(usize::from_str(args[0]))); + map.lock().unwrap().remove(&usize::from_str(args[0])?); Ok(()) }); shell.new_command("list", "List all values", 0, |io, map, _| { diff --git a/src/lib.rs b/src/lib.rs index 81b812afd2..1d2a6ee8f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,7 @@ pub enum ExecError { /// Other error that may have happen during command execution Other(Box), } -use ExecError::*; +use crate::ExecError::*; impl fmt::Display for ExecError { fn fmt(&self, format: &mut fmt::Formatter) -> fmt::Result { @@ -371,8 +371,8 @@ mod builtins { pub fn history_cmd() -> Command { return Command::new("history".to_string(), "Print commands history or run a command from it".to_string(), 0, Box::new(|io, shell, args| { if !args.is_empty() { - let i = try!(usize::from_str(args[0])); - let cmd = try!(shell.get_history().get(i).ok_or_else(|| ExecError::InvalidHistory(i))); + let i = usize::from_str(args[0])?; + let cmd = shell.get_history().get(i).ok_or_else(|| ExecError::InvalidHistory(i))?; return shell.eval(io, &cmd); } else { shell.get_history().print(io);