shadow_rs::utility::units

Trait Unit

source
pub trait Unit: Sized {
    type U;
    type T: Prefix;

    // Required methods
    fn value(&self) -> Self::U;
    fn prefix(&self) -> Self::T;
    fn suffixes() -> &'static [&'static str];
    fn convert(&self, prefix: Self::T) -> Result<Self, String>
       where Self: Sized;
    fn convert_lossy(&self, prefix: Self::T) -> Self
       where Self: Sized;
}
Expand description

A unit containing a value (ex: an integer), a prefix (ex: an enum), and allowed constant suffix strings.

Required Associated Types§

Required Methods§

source

fn value(&self) -> Self::U

The value of the unit in the size of its current prefix.

source

fn prefix(&self) -> Self::T

The current prefix.

source

fn suffixes() -> &'static [&'static str]

source

fn convert(&self, prefix: Self::T) -> Result<Self, String>
where Self: Sized,

Convert value to a different prefix, but return an error if the conversion cannot be done without possibly losing precision.

source

fn convert_lossy(&self, prefix: Self::T) -> Self
where Self: Sized,

Convert value to a different prefix, even if it loses precision.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Prefix> Unit for BitsPerSec<T>

source§

type U = u64

source§

type T = T

source§

impl<T: Prefix> Unit for Bytes<T>

source§

type U = u64

source§

type T = T

source§

impl<T: Prefix> Unit for Time<T>

source§

type U = u64

source§

type T = T