Skip to main content

UnitFromType

Trait UnitFromType 

Source
pub trait UnitFromType {
    // Provided method
    fn unit_from_type() -> Unit { ... }
}
Expand description

A trait to derive Unit from a type. This trait bridges the gap between (external) types representing physical quantities (such as e.g. the Quantity type from the uom crate) and Unit.

Provided Methods§

Source

fn unit_from_type() -> Unit

This function derives an Unit from any type which implements UnitFromType. Its default implementation returns an Unit where all exponents are zero.

§Examples
use dyn_quantity::UnitFromType;
use uom::si::f64::Length;

// 64-bit floats do not represent a physical quantity
let exp = f64::unit_from_type();
assert_eq!(exp.meter, 0);

// The "Length" type alias from the uom crate represents a physical quantity (length)
let exp = Length::unit_from_type();
assert_eq!(exp.meter, 1);

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 UnitFromType for f64

Source§

impl UnitFromType for Complex<f64>

Source§

impl<L, M, T, I, Th, N, J, K> UnitFromType for Quantity<ISQ<L, M, T, I, Th, N, J, K>, SI<f64>, f64>
where L: Integer, M: Integer, T: Integer, I: Integer, Th: Integer, N: Integer, J: Integer, K: ?Sized,

Available on crate feature uom only.

Implementors§