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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so 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