Skip to content

Commit

Permalink
fix a lot of Clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
oconnor663 committed Dec 22, 2023
1 parent 0708108 commit 5c70737
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/bin/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i32>().expect("not a valid status"))
.unwrap_or(0);
exit(status);
}
37 changes: 15 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1227,7 +1224,7 @@ fn start_argv(argv: &[OsString], context: IoContext) -> io::Result<ChildHandle>
let command_string = format!("{:?}", argv);
Ok(ChildHandle {
child: shared_child,
command_string: command_string,
command_string,
})
}

Expand All @@ -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(),
}))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1512,9 +1509,11 @@ enum IoExpressionInner {
BeforeSpawn(BeforeSpawnHook),
}

type HookFn = Arc<dyn Fn(&mut Command) -> io::Result<()> + Send + Sync>;

#[derive(Clone)]
struct BeforeSpawnHook {
inner: Arc<dyn Fn(&mut Command) -> io::Result<()> + Send + Sync>,
inner: HookFn,
}

impl BeforeSpawnHook {
Expand Down Expand Up @@ -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(_)))
}
}

Expand Down Expand Up @@ -1892,7 +1885,7 @@ impl OutputCaptureContext {
}

fn write_pipe(&self) -> io::Result<os_pipe::PipeWriter> {
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()
}

Expand Down Expand Up @@ -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<usize> {
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()?;
}
Expand Down

0 comments on commit 5c70737

Please sign in to comment.