diff --git a/src/chrony.rs b/src/chrony.rs index 0a7cb5c..8f0b5a2 100644 --- a/src/chrony.rs +++ b/src/chrony.rs @@ -114,8 +114,8 @@ impl ChronyClient { } } async fn query(&self, request: RequestBody) -> Result { - let server = self.server.clone(); - let client_options = self.client_options.clone(); + let server = self.server; + let client_options = self.client_options; tokio::task::spawn_blocking(move || blocking_query(request, client_options, &server)) .await .map_err(|e| { diff --git a/src/chrony_refclock.rs b/src/chrony_refclock.rs index 446939b..342fefa 100644 --- a/src/chrony_refclock.rs +++ b/src/chrony_refclock.rs @@ -42,16 +42,8 @@ impl ChimemonTarget for ChronySockServer { { let frame = ChronyTimeReport { tv: timeval { - tv_sec: tr - .system_time - .timestamp() - .try_into() - .unwrap_or_default(), - tv_usec: tr - .system_time - .timestamp() - .try_into() - .unwrap_or_default(), + tv_sec: tr.system_time.timestamp(), + tv_usec: tr.system_time.timestamp(), }, offset: tr.offset.num_nanoseconds().unwrap() as f64 / 1e9, leap: if tr.leap_flag { 1 } else { 0 }, diff --git a/src/main.rs b/src/main.rs index c2b5140..6f1d7a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,11 +68,8 @@ async fn main() -> Result<(), Box> { } else { None }; - match chrony { - Some(c) => { - tasks.push(tokio::spawn(c.run(sourcechan.clone()))); - } - None => (), + if let Some(c) = chrony { + tasks.push(tokio::spawn(c.run(sourcechan.clone()))); }; let hwmon = if config.sources.hwmon.enabled { @@ -80,11 +77,8 @@ async fn main() -> Result<(), Box> { } else { None }; - match hwmon { - Some(hwmon) => { - tasks.push(tokio::spawn(hwmon.run(sourcechan.clone()))); - } - None => (), + if let Some(hwmon) = hwmon { + tasks.push(tokio::spawn(hwmon.run(sourcechan.clone()))); }; let uccm = if config.sources.uccm.enabled { @@ -94,11 +88,8 @@ async fn main() -> Result<(), Box> { info!("UCCMMonitor not configured"); None }; - match uccm { - Some(uccm) => { - tasks.push(tokio::spawn(uccm.run(sourcechan.clone()))); - } - None => (), + if let Some(uccm) = uccm { + tasks.push(tokio::spawn(uccm.run(sourcechan.clone()))); }; let chrony_refclock = if config.targets.chrony.enabled { @@ -106,11 +97,8 @@ async fn main() -> Result<(), Box> { } else { None }; - match chrony_refclock { - Some(chrony_refclock) => { - tasks.push(tokio::spawn(chrony_refclock.run(sourcechan.subscribe()))); - } - None => (), + if let Some(chrony_refclock) = chrony_refclock { + tasks.push(tokio::spawn(chrony_refclock.run(sourcechan.subscribe()))); }; let mut influxrx = sourcechan.subscribe(); diff --git a/src/uccm.rs b/src/uccm.rs index 47bfc13..5fd60f8 100644 --- a/src/uccm.rs +++ b/src/uccm.rs @@ -206,7 +206,7 @@ impl TryFrom<&[u8]> for UCCMTODReport { fn try_from(strbuf: &[u8]) -> Result { debug!("TOD buffer: `{:#?}`", String::from_utf8(strbuf.to_vec())); let resp: Vec = strbuf - .split(|c| *c == ' ' as u8) + .split(|c| *c == b' ') .map(|x| u8::from_str_radix(str::from_utf8(x).unwrap_or(""), 16).unwrap_or(0)) .collect(); let mut rdr = Cursor::new(resp); @@ -257,9 +257,7 @@ impl TryFrom<&str> for UCCMLoopDiagReport { "No lines!", ))??; let ocxo_val = ocxo_line - .split(':') - .skip(1) - .next() + .split(':').nth(1) .ok_or(std::io::Error::new( std::io::ErrorKind::InvalidData, "no colon!", @@ -282,7 +280,7 @@ impl TryFrom<&str> for UCCMGPSSatsReport { "Invalid response (expected `NSATS CNOS`)", ))?; let nsats = nsats.parse::().map_err(|e| { - std::io::Error::new(std::io::ErrorKind::InvalidData, "Invalid number of sats") + std::io::Error::new(std::io::ErrorKind::InvalidData, format!("Invalid number of sats ({e})")) })?; let tracked_svs = cnos .split(',') @@ -321,7 +319,7 @@ impl UCCMMonitor { rx, tx, info: None, - config: config, + config, } } @@ -422,11 +420,7 @@ impl UCCMMonitor { system_time: sysnow, offset, leaps: tod.leaps as isize, - leap_flag: if tod.flags.contains(UCCMFlags::LEAP_FLAG) { - true - } else { - false - }, + leap_flag: tod.flags.contains(UCCMFlags::LEAP_FLAG), valid, })) .expect("Unable to send to channel");