Skip to content

Commit

Permalink
Makes the latest clippy lints happy
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkar598 committed Jun 23, 2024
1 parent daf1426 commit 967614c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn main() {
if let Err(e) = port.read_exact(&mut serial_char_buf) {
match e.kind() {
io::ErrorKind::TimedOut | io::ErrorKind::UnexpectedEof => continue,
_ => panic!("IO error when reading character: {}", e),
_ => panic!("IO error when reading character: {e}"),
}
}

Expand Down Expand Up @@ -82,7 +82,7 @@ fn main() {
}
// If the port could not be opened, print an error and exit
Err(e) => {
eprintln!("Failed to open serial connection. Error: {}", e);
eprintln!("Failed to open serial connection. Error: {e}");
std::process::exit(1);
}
}
Expand All @@ -109,8 +109,8 @@ fn process_cmds(
["signal", pid, signal] => signal::send(pid, signal),
["poll"] => Ok(poll::send_poll_data(poll_data)),
_ => {
eprintln!("Unknown cmd: {}", cmd);
Err(format!("Unknown cmd: {}", cmd))
eprintln!("Unknown cmd: {cmd}");
Err(format!("Unknown cmd: {cmd}"))
}
}
}
14 changes: 7 additions & 7 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ pub fn process(
let process = match decode(b_process) {
Ok(dec_vec) if dec_vec.is_empty() => String::new(),
Ok(dec_vec) => String::from_utf8(dec_vec).expect("Invalid UTF8 for exec path"),
Err(e) => return Err(format!("Error decoding exec path: {}", e)),
Err(e) => return Err(format!("Error decoding exec path: {e}")),
};

let raw_args = match decode(b_args) {
Ok(dec_vec) if dec_vec.is_empty() => String::new(),
Ok(dec_vec) => String::from_utf8(dec_vec).expect("Invalid UTF8 for exec args"),
Err(e) => return Err(format!("Error decoding exec args: {}", e)),
Err(e) => return Err(format!("Error decoding exec args: {e}")),
};
let args = raw_args.split('\0').collect::<Vec<&str>>();

let raw_env_vars = match decode(b_env_vars) {
Ok(dec_vec) if dec_vec.is_empty() => String::new(),
Ok(dec_vec) => String::from_utf8(dec_vec).expect("Invalid UTF8 for exec env args"),
Err(e) => return Err(format!("Error decoding exec env vars: {}", e)),
Err(e) => return Err(format!("Error decoding exec env vars: {e}")),
};

// Handle environment vars parsing into tuples
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn process(
.stderr(Redirection::Pipe)
.popen()
{
Err(e) => return Err(format!("Failed to create process: {}", e)),
Err(e) => return Err(format!("Failed to create process: {e}")),
Ok(proc) => proc,
};

Expand All @@ -126,7 +126,7 @@ pub fn process(
data.1.map(|dat| String::from_utf8_lossy(&dat).into_owned()),
)
}
Err(e) => panic!("Error while reading comms: {}", e),
Err(e) => panic!("Error while reading comms: {e}"),
}
};
push_possible_output(comm_data, pid, &poll_data);
Expand All @@ -140,7 +140,7 @@ pub fn process(
ExitStatus::Exited(code) => code,
ExitStatus::Undetermined => 256,
ExitStatus::Signaled(signal) => 256 + u32::from(signal),
ExitStatus::Other(what) => panic!("Unknown ExitStatus: {}", what),
ExitStatus::Other(what) => panic!("Unknown ExitStatus: {what}"),
};
poll_data.lock().unwrap().push(PollData {
typ: PollType::PidExit,
Expand All @@ -153,7 +153,7 @@ pub fn process(
}
});

Ok(format!("{}\n", pid))
Ok(format!("{pid}\n"))
}

fn push_possible_output(
Expand Down
7 changes: 2 additions & 5 deletions src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ pub fn send(pid: &&str, signal: &&str) -> Result<String, String> {
nix::unistd::Pid::from_raw(pid.parse::<i32>().expect("Malformed pid")),
sig,
) {
Ok(_) => Ok(String::new()),
Err(e) => Err(format!(
"Error sending signal {} to pid {}: {}",
sig, pid, e
)),
Ok(()) => Ok(String::new()),
Err(e) => Err(format!("Error sending signal {sig} to pid {pid}: {e}")),
}
}

Expand Down

0 comments on commit 967614c

Please sign in to comment.