diff --git a/src/bin/status.rs b/src/bin/status.rs index 450e342..9ac2515 100644 --- a/src/bin/status.rs +++ b/src/bin/status.rs @@ -6,7 +6,7 @@ use std::process::exit; fn main() { let status = args() .nth(1) - .map(|s| i32::from_str_radix(&s, 10).expect("not a valid status")) + .map(|s| s.parse::().expect("not a valid status")) .unwrap_or(0); exit(status); } diff --git a/src/lib.rs b/src/lib.rs index 873984e..3de3f72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -154,19 +154,16 @@ where /// # Example /// /// ``` -/// /// use duct::cmd; /// use std::path::Path; /// -/// fn main() { -/// let arg1 = "foo"; -/// let arg2 = "bar".to_owned(); -/// let arg3 = Path::new("baz"); +/// let arg1 = "foo"; +/// let arg2 = "bar".to_owned(); +/// let arg3 = Path::new("baz"); /// -/// let output = cmd!("echo", arg1, arg2, arg3).read(); +/// let output = cmd!("echo", arg1, arg2, arg3).read(); /// -/// assert_eq!("foo bar baz", output.unwrap()); -/// } +/// assert_eq!("foo bar baz", output.unwrap()); /// ``` #[macro_export] macro_rules! cmd { @@ -1227,7 +1224,7 @@ fn start_argv(argv: &[OsString], context: IoContext) -> io::Result let command_string = format!("{:?}", argv); Ok(ChildHandle { child: shared_child, - command_string: command_string, + command_string, }) } @@ -1245,7 +1242,7 @@ impl ChildHandle { }; if let Some(status) = maybe_status { Ok(Some(ExpressionStatus { - status: status, + status, checked: true, command: self.command_string.clone(), })) @@ -1283,8 +1280,8 @@ impl PipeHandle { let right_result = right.0.start(right_context); match right_result { Ok(right_handle) => Ok(PipeHandle { - left_handle: left_handle, - right_handle: right_handle, + left_handle, + right_handle, }), Err(e) => { // Realistically, kill should never return an error. If it @@ -1512,9 +1509,11 @@ enum IoExpressionInner { BeforeSpawn(BeforeSpawnHook), } +type HookFn = Arc io::Result<()> + Send + Sync>; + #[derive(Clone)] struct BeforeSpawnHook { - inner: Arc io::Result<()> + Send + Sync>, + inner: HookFn, } impl BeforeSpawnHook { @@ -1849,13 +1848,7 @@ impl WaitMode { // running expression is finished (that is, when the thread is // guaranteed to finish soon). Blocking waits should always join, even // in the presence of errors. - if let WaitMode::Blocking = self { - true - } else if let Ok(Some(_)) = expression_result { - true - } else { - false - } + matches!(self, WaitMode::Blocking) || matches!(expression_result, Ok(Some(_))) } } @@ -1892,7 +1885,7 @@ impl OutputCaptureContext { } fn write_pipe(&self) -> io::Result { - let (_, writer) = self.pair.get_or_try_init(|| os_pipe::pipe())?; + let (_, writer) = self.pair.get_or_try_init(os_pipe::pipe)?; writer.try_clone() } @@ -2038,7 +2031,7 @@ impl<'a> Read for &'a ReaderHandle { /// error, just as [`run`](struct.Expression.html#method.run) would. fn read(&mut self, buf: &mut [u8]) -> io::Result { let n = (&self.reader).read(buf)?; - if n == 0 && buf.len() > 0 { + if n == 0 && !buf.is_empty() { // EOF detected. Wait on the child to clean it up before returning. self.handle.wait()?; }