Trait Quantity

Source
pub trait Quantity:
    Copy
    + Debug
    + Sized {
    // Required methods
    fn pack(_: f64) -> Self;
    fn unpack(self) -> f64;
    fn unwrap(self) -> f64;
    fn into_option(self) -> Option<f64>;

    // Provided methods
    fn approx_eq<RHS, TOL>(self, other: RHS, tol: TOL) -> bool
       where Self: From<RHS> + From<TOL> + Quantity { ... }
    fn abs(self) -> Self { ... }
}
Expand description

A quantity is a common super trait for types that represent units of measurement.

Required Methods§

Source

fn pack(_: f64) -> Self

Create a new instance of self by wrapping a value

Source

fn unpack(self) -> f64

Unpack a wrapped value without any error checking.

Source

fn unwrap(self) -> f64

Unwrap the value from the new type and check for validity, panic if contents are invalid.

Source

fn into_option(self) -> Option<f64>

Convert into an option that is None if the content is invalid.

Provided Methods§

Source

fn approx_eq<RHS, TOL>(self, other: RHS, tol: TOL) -> bool
where Self: From<RHS> + From<TOL> + Quantity,

Test whether these two values are close

Source

fn abs(self) -> Self

Get the absolute value.

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.

Implementations on Foreign Types§

Source§

impl Quantity for f64

Source§

fn pack(val: f64) -> f64

Source§

fn unpack(self) -> f64

Source§

fn unwrap(self) -> f64

Source§

fn into_option(self) -> Option<f64>

Source§

impl Quantity for u8

Source§

fn pack(val: f64) -> u8

Source§

fn unpack(self) -> f64

Source§

fn unwrap(self) -> f64

Source§

fn into_option(self) -> Option<f64>

Implementors§