pub struct Bandwidth { /* private fields */ }Expand description
Represents a rate at which data is transferred
While bandwidth is typically thought of as an amount of data over a fixed
amount of time (bytes per second, for example), in this case we internally
represent bandwidth as the inverse: an amount of time to send a fixed amount
of data (nanoseconds per kibibyte or 1024 bytes, in this case). This allows for
some of the math operations needed on Bandwidth to avoid division, while
reducing the likelihood of panicking due to overflow.
The maximum (non-infinite) value that can be represented is ~1 TB/second.
Implementations§
Source§impl Bandwidth
impl Bandwidth
pub const ZERO: Bandwidth
pub const INFINITY: Bandwidth
Sourcepub const fn new(bytes: u64, interval: Duration) -> Self
pub const fn new(bytes: u64, interval: Duration) -> Self
Constructs a new Bandwidth with the given bytes per interval
pub fn serialize(self) -> u64
pub fn deserialize(value: u64) -> Self
Sourcepub fn as_bytes_per_second(&self) -> u64
pub fn as_bytes_per_second(&self) -> u64
Represents the bandwidth as bytes per second
Trait Implementations§
Source§impl Div<Bandwidth> for u64
Divides a count of bytes represented as a u64 by the given Bandwidth
impl Div<Bandwidth> for u64
Divides a count of bytes represented as a u64 by the given Bandwidth
Since Bandwidth is a rate of bytes over a time period, this division
results in a Duration being returned, representing how long a path
with the given Bandwidth would take to transmit the given number of
bytes.