Skip to content

Commit

Permalink
Merge pull request #4 from expobrain/rust_2018
Browse files Browse the repository at this point in the history
Migrated to Rust 2018
  • Loading branch information
phsym authored Aug 25, 2019
2 parents ee4291f + dd1fac2 commit 3b3c925
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions examples/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
});
Expand Down
2 changes: 1 addition & 1 deletion examples/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
});

Expand Down
6 changes: 3 additions & 3 deletions examples/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _| {
Expand Down
6 changes: 3 additions & 3 deletions examples/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _| {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub enum ExecError {
/// Other error that may have happen during command execution
Other(Box<Error>),
}
use ExecError::*;
use crate::ExecError::*;

impl fmt::Display for ExecError {
fn fmt(&self, format: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -371,8 +371,8 @@ mod builtins {
pub fn history_cmd<T>() -> Command<T> {
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);
Expand Down

0 comments on commit 3b3c925

Please sign in to comment.