FormattedBandwidth

Struct FormattedBandwidth 

Source
pub struct FormattedBandwidth(/* private fields */);
Expand description

A wrapper type that allows you to Display a Bandwidth

Implementations§

Source§

impl FormattedBandwidth

Source

pub fn get_ref(&self) -> &Bandwidth

👎Deprecated since 0.1.4: please use core::ops::Deref instead

Returns a reference to the Bandwidth that is being formatted.

Source

pub fn fmt_integer(&self, f: &mut Formatter<'_>) -> Result

Enabling the display-integer feature will display integer values only

This method is preserved for backward compatibility and custom formatting.

Source

pub fn fmt_decimal(&self, f: &mut Formatter<'_>) -> Result

Disabling the display-integer feature will display decimal values

This method is preserved for custom formatting.

Methods from Deref<Target = Bandwidth>§

Source

pub const MAX: Bandwidth

Source

pub const ZERO: Bandwidth

Source

pub fn is_zero(&self) -> bool

Returns true if this Bandwidth has zero speed.

§Examples
use bandwidth::Bandwidth;

assert!(Bandwidth::ZERO.is_zero());
assert!(Bandwidth::new(0, 0).is_zero());
assert!(Bandwidth::from_bps(0).is_zero());
assert!(Bandwidth::from_gbps(0).is_zero());

assert!(!Bandwidth::new(1, 1).is_zero());
assert!(!Bandwidth::from_bps(1).is_zero());
assert!(!Bandwidth::from_gbps(1).is_zero());
Source

pub fn as_gbps(&self) -> u64

Returns the number of whole gbps contained by this Bandwidth.

The returned value does not include the fractional(bps) part of the Bandwidth, which can be obtained using subgbps_bps.

§Examples
use bandwidth::Bandwidth;

let Bandwidth = Bandwidth::new(5, 730023852);
assert_eq!(Bandwidth.as_gbps(), 5);

To determine the total number of gbps represented by the Bandwidth including the fractional part, use as_gbps_f64 or as_gbps_f32

Source

pub fn subgbps_mbps(&self) -> u32

Returns the fractional part of this Bandwidth, in whole mbps.

This method does not return the speed of the Bandwidth when represented by mbps. The returned number always represents a fractional portion of a gbps (i.e., it is less than one thousand).

§Examples
use bandwidth::Bandwidth;

let Bandwidth = Bandwidth::from_mbps(5432);
assert_eq!(Bandwidth.as_gbps(), 5);
assert_eq!(Bandwidth.subgbps_mbps(), 432);
Source

pub fn subgbps_kbps(&self) -> u32

Returns the fractional part of this Bandwidth, in whole kbps.

This method does not return the speed of the Bandwidth when represented by kbps. The returned number always represents a fractional portion of a gbps (i.e., it is less than one million).

§Examples
use bandwidth::Bandwidth;

let Bandwidth = Bandwidth::from_kbps(1_234_567);
assert_eq!(Bandwidth.as_gbps(), 1);
assert_eq!(Bandwidth.subgbps_kbps(), 234_567);
Source

pub fn subgbps_bps(&self) -> u32

Returns the fractional part of this Bandwidth, in bps.

This method does not return the speed of the Bandwidth when represented by bps. The returned number always represents a fractional portion of a gbps (i.e., it is less than one billion).

§Examples
use bandwidth::Bandwidth;

let Bandwidth = Bandwidth::from_mbps(5010);
assert_eq!(Bandwidth.as_gbps(), 5);
assert_eq!(Bandwidth.subgbps_bps(), 10_000_000);
Source

pub fn as_mbps(&self) -> u128

Returns the total number of whole mbps contained by this Bandwidth.

§Examples
use bandwidth::Bandwidth;

let Bandwidth = Bandwidth::new(5, 730023852);
assert_eq!(Bandwidth.as_mbps(), 5730);
Source

pub fn as_kbps(&self) -> u128

Returns the total number of whole kbps contained by this Bandwidth.

§Examples
use bandwidth::Bandwidth;

let Bandwidth = Bandwidth::new(5, 730023852);
assert_eq!(Bandwidth.as_kbps(), 5730023);
Source

pub fn as_bps(&self) -> u128

Returns the total number of bps contained by this Bandwidth.

§Examples
use bandwidth::Bandwidth;

let Bandwidth = Bandwidth::new(5, 730023852);
assert_eq!(Bandwidth.as_bps(), 5730023852);
Source

pub fn as_gbps_f64(&self) -> f64

Returns the number of gbps contained by this Bandwidth as f64.

The returned value does include the fractional (bps) part of the Bandwidth.

§Examples
use bandwidth::Bandwidth;

let bw = Bandwidth::new(2, 700_000_000);
assert_eq!(bw.as_gbps_f64(), 2.7);
Source

pub fn as_gbps_f32(&self) -> f32

Returns the number of gbps contained by this Bandwidth as f32.

The returned value does include the fractional (bps) part of the Bandwidth.

§Examples
use bandwidth::Bandwidth;

let bw = Bandwidth::new(2, 700_000_000);
assert_eq!(bw.as_gbps_f32(), 2.7);

Trait Implementations§

Source§

impl Clone for FormattedBandwidth

Source§

fn clone(&self) -> FormattedBandwidth

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FormattedBandwidth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for FormattedBandwidth

Source§

type Target = Bandwidth

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Bandwidth

Dereferences the value.
Source§

impl DerefMut for FormattedBandwidth

Source§

fn deref_mut(&mut self) -> &mut Bandwidth

Mutably dereferences the value.
Source§

impl Display for FormattedBandwidth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.