cargo fmt

This commit is contained in:
Jeremy Wall 2021-12-30 18:57:55 -05:00
parent eb1d17407e
commit 3b9daf442a
3 changed files with 22 additions and 16 deletions

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
use notify::DebouncedEvent; use notify::DebouncedEvent;
#[derive(PartialEq,Clone)] #[derive(PartialEq, Clone)]
pub enum WatchEventType { pub enum WatchEventType {
Touched, Touched,
Changed, Changed,

View File

@ -16,9 +16,8 @@ use std::time::Duration;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use traits::Process;
use error::CommandError; use error::CommandError;
use traits::Process;
fn env_var_to_tuple(var: &str) -> (String, String) { fn env_var_to_tuple(var: &str) -> (String, String) {
let mut vs = var.split('='); let mut vs = var.split('=');
@ -26,13 +25,16 @@ fn env_var_to_tuple(var: &str) -> (String, String) {
return match vs.next() { return match vs.next() {
Some(val) => (String::from(name), String::from(val)), Some(val) => (String::from(name), String::from(val)),
None => (String::from(name), "".to_string()), None => (String::from(name), "".to_string()),
} };
} }
("".to_string(), "".to_string()) ("".to_string(), "".to_string())
} }
pub fn run_cmd(cmd: &str, env: &Option<Vec<&str>>) -> Result<i32, CommandError> { pub fn run_cmd(cmd: &str, env: &Option<Vec<&str>>) -> Result<i32, CommandError> {
let args = cmd.split(' ').filter(|s| !s.is_empty()).collect::<Vec<&str>>(); let args = cmd
.split(' ')
.filter(|s| !s.is_empty())
.collect::<Vec<&str>>();
if args.len() < 1 { if args.len() < 1 {
return Err(CommandError::new("Empty command string passed in")); return Err(CommandError::new("Empty command string passed in"));
} }
@ -55,7 +57,7 @@ pub fn run_cmd(cmd: &str, env: &Option<Vec<&str>>) -> Result<i32, CommandError>
}, },
// TODO(jeremy): We should not swallow this error. // TODO(jeremy): We should not swallow this error.
Err(_) => Err(CommandError::new("Error running command")), Err(_) => Err(CommandError::new("Error running command")),
} };
} }
fn is_cmd_success(cmd: &str, env: Option<Vec<&str>>) -> bool { fn is_cmd_success(cmd: &str, env: Option<Vec<&str>>) -> bool {
@ -74,11 +76,13 @@ pub struct ExecProcess<'a> {
} }
impl<'a> ExecProcess<'a> { impl<'a> ExecProcess<'a> {
pub fn new(test_cmd: &'a str, pub fn new(
cmd: &'a str, test_cmd: &'a str,
negate: bool, cmd: &'a str,
env: Option<Vec<&'a str>>, negate: bool,
poll: Duration) -> ExecProcess<'a> { env: Option<Vec<&'a str>>,
poll: Duration,
) -> ExecProcess<'a> {
ExecProcess { ExecProcess {
test_cmd: test_cmd, test_cmd: test_cmd,
negate: negate, negate: negate,

View File

@ -14,9 +14,9 @@
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use traits::Process;
use error::CommandError; use error::CommandError;
use exec::run_cmd; use exec::run_cmd;
use traits::Process;
pub struct TimerProcess<'a> { pub struct TimerProcess<'a> {
cmd: &'a str, cmd: &'a str,
@ -26,10 +26,12 @@ pub struct TimerProcess<'a> {
} }
impl<'a> TimerProcess<'a> { impl<'a> TimerProcess<'a> {
pub fn new(cmd: &'a str, pub fn new(
env: Option<Vec<&'a str>>, cmd: &'a str,
poll_duration: Duration, env: Option<Vec<&'a str>>,
max_repeat: Option<u32>) -> TimerProcess<'a> { poll_duration: Duration,
max_repeat: Option<u32>,
) -> TimerProcess<'a> {
TimerProcess { TimerProcess {
cmd: cmd, cmd: cmd,
env: env, env: env,