diff --git a/backend/common/src/byte_size.rs b/backend/common/src/byte_size.rs index 9d1b577..65fdb68 100644 --- a/backend/common/src/byte_size.rs +++ b/backend/common/src/byte_size.rs @@ -1,6 +1,6 @@ -use anyhow::{ anyhow, Error }; +use anyhow::{anyhow, Error}; -#[derive(Copy,Clone,Debug)] +#[derive(Copy, Clone, Debug)] pub struct ByteSize(usize); impl ByteSize { @@ -38,9 +38,14 @@ impl std::str::FromStr for ByteSize { "KiB" | "Ki" => n * 1024, "MiB" | "Mi" => n * 1024 * 1024, "GiB" | "Gi" => n * 1024 * 1024 * 1024, - _ => return Err(anyhow!("\ + _ => { + return Err(anyhow!( + "\ Cannot parse into bytes; suffix is '{}', but expecting one of \ - B,b, kB,K,k, MB,M,m, GB,G,g, KiB,Ki, MiB,Mi, GiB,Gi", suffix)) + B,b, kB,K,k, MB,M,m, GB,G,g, KiB,Ki, MiB,Mi, GiB,Gi", + suffix + )) + } }; Ok(ByteSize(n)) } @@ -52,34 +57,27 @@ impl std::str::FromStr for ByteSize { mod test { use crate::byte_size::ByteSize; - #[test] fn can_parse_valid_strings() { let cases = vec![ ("100", 100), ("100B", 100), ("100b", 100), - ("20kB", 20 * 1000), ("20 kB", 20 * 1000), ("20K", 20 * 1000), (" 20k", 20 * 1000), - ("1MB", 1 * 1000 * 1000), ("1M", 1 * 1000 * 1000), ("1m", 1 * 1000 * 1000), ("1 m", 1 * 1000 * 1000), - ("1GB", 1 * 1000 * 1000 * 1000), ("1G", 1 * 1000 * 1000 * 1000), ("1g", 1 * 1000 * 1000 * 1000), - ("1KiB", 1 * 1024), ("1Ki", 1 * 1024), - ("1MiB", 1 * 1024 * 1024), ("1Mi", 1 * 1024 * 1024), - ("1GiB", 1 * 1024 * 1024 * 1024), ("1Gi", 1 * 1024 * 1024 * 1024), (" 1 Gi ", 1 * 1024 * 1024 * 1024), @@ -90,5 +88,4 @@ mod test { assert_eq!(b.into_bytes(), expected); } } - -} \ No newline at end of file +} diff --git a/backend/common/src/lib.rs b/backend/common/src/lib.rs index d73b839..484185b 100644 --- a/backend/common/src/lib.rs +++ b/backend/common/src/lib.rs @@ -1,13 +1,13 @@ +pub mod byte_size; pub mod http_utils; pub mod id_type; pub mod internal_messages; pub mod node_message; pub mod node_types; pub mod ready_chunks_all; +pub mod rolling_total; pub mod time; pub mod ws_client; -pub mod rolling_total; -pub mod byte_size; mod assign_id; mod dense_map; diff --git a/backend/common/src/rolling_total.rs b/backend/common/src/rolling_total.rs index 060fca5..8a3cee7 100644 --- a/backend/common/src/rolling_total.rs +++ b/backend/common/src/rolling_total.rs @@ -1,6 +1,6 @@ -use std::time::{ Duration, Instant }; -use num_traits::{ Zero, SaturatingAdd, SaturatingSub }; +use num_traits::{SaturatingAdd, SaturatingSub, Zero}; use std::collections::VecDeque; +use std::time::{Duration, Instant}; /// Build an object responsible for keeping track of a rolling total. /// It does this in constant time and using memory proportional to the @@ -8,7 +8,7 @@ use std::collections::VecDeque; pub struct RollingTotalBuilder { window_size_multiple: usize, granularity: Duration, - time_source: Time + time_source: Time, } impl RollingTotalBuilder { @@ -19,7 +19,7 @@ impl RollingTotalBuilder { Self { window_size_multiple: 10, granularity: Duration::from_secs(1), - time_source: SystemTimeSource + time_source: SystemTimeSource, } } @@ -28,7 +28,7 @@ impl RollingTotalBuilder { RollingTotalBuilder { window_size_multiple: self.window_size_multiple, granularity: self.granularity, - time_source: val + time_source: val, } } @@ -52,11 +52,12 @@ impl RollingTotalBuilder { } } -impl RollingTotalBuilder