From c124f9fff690a42ea5fb490e4c7e512ba8448951 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 13 Jun 2024 16:54:35 +0200 Subject: cargo update + `time` update, fix for `Instant` deprecation --- src/config.rs | 2 +- src/routes/start.rs | 4 ++-- src/services/ping.rs | 12 ++++++------ src/storage.rs | 4 +++- 4 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index bfb28be..7c91c08 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,7 +7,7 @@ use crate::auth; pub struct Config { pub serveraddr: String, pub pingtimeout: i64, - pub pingthreshold: i64, + pub pingthreshold: u64, pub timeoffset: i8, pub auth: Auth, } diff --git a/src/routes/start.rs b/src/routes/start.rs index 192a54a..0b6b38b 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs @@ -128,14 +128,14 @@ fn setup_ping(state: Arc, device: Device) -> String { uuid_ret } -fn get_eta(times: Option>) -> i64 { +fn get_eta(times: Option>) -> u64 { let times = if let Some(times) = times { times } else { vec![0] }; - times.iter().sum::() / i64::try_from(times.len()).unwrap() + times.iter().sum::() / u64::try_from(times.len()).unwrap() } #[derive(Deserialize, ToSchema)] diff --git a/src/services/ping.rs b/src/services/ping.rs index 4e0ffcf..69c911f 100644 --- a/src/services/ping.rs +++ b/src/services/ping.rs @@ -2,8 +2,8 @@ use crate::config::Config; use crate::storage::Device; use dashmap::DashMap; use ipnetwork::IpNetwork; -use std::fmt::Display; -use time::{Duration, Instant}; +use std::{fmt::Display, time::Instant}; +use time::Duration; use tokio::sync::broadcast::Sender; use tracing::{debug, error, trace}; @@ -12,7 +12,7 @@ pub type StatusMap = DashMap; #[derive(Debug, Clone)] pub struct Value { pub ip: IpNetwork, - pub eta: i64, + pub eta: u64, pub online: bool, } @@ -56,12 +56,12 @@ pub async fn spawn( let _ = tx.send(msg.clone()); if msg.command == BroadcastCommands::Success { - if timer.elapsed().whole_seconds() > config.pingthreshold { + if timer.elapsed().as_secs() > config.pingthreshold { let newtimes = if let Some(mut oldtimes) = device.times { - oldtimes.push(timer.elapsed().whole_seconds()); + oldtimes.push(timer.elapsed().as_secs()); oldtimes } else { - vec![timer.elapsed().whole_seconds()] + vec![timer.elapsed().as_secs()] }; let updatedev = Device { diff --git a/src/storage.rs b/src/storage.rs index 52c2e60..90ff1b4 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -19,7 +19,7 @@ pub struct Device { pub mac: MacAddress, pub broadcast_addr: String, pub ip: Option, - pub times: Option>, + pub times: Option>, } impl Device { @@ -59,6 +59,8 @@ impl Device { } } +// Dead Code allowed because of use in OpenApi Macro (not really dead code) +#[allow(dead_code)] #[derive(ToSchema)] #[schema(as = Device)] pub struct DeviceSchema { -- cgit v1.2.3