mirror of
https://github.com/kristoferssolo/traxor.git
synced 2025-10-21 20:10:35 +00:00
21 lines
576 B
Rust
21 lines
576 B
Rust
use super::unit::{Unit, UnitDisplay};
|
|
use crate::impl_unit_newtype;
|
|
use std::fmt::Display;
|
|
|
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
|
|
pub struct NetSpeed(Unit);
|
|
impl_unit_newtype!(NetSpeed);
|
|
|
|
impl NetSpeed {
|
|
pub fn new(bytes_per_second: u64) -> Self {
|
|
Self(Unit::from_raw(bytes_per_second))
|
|
}
|
|
}
|
|
|
|
impl Display for NetSpeed {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
const UNITS: &[&str] = &["B/s", "KB/s", "MB/s", "GB/s", "TB/s", "PB/s"];
|
|
write!(f, "{}", UnitDisplay::new(&self.0, UNITS))
|
|
}
|
|
}
|