Struct de_uom::Quantity

source ·
pub struct Quantity<const U: i32>(pub(crate) f32);
Expand description

A quantity with associated units.

The units are either base SI units and several extensions (for example m, s, px) or derived units (for example rad, m/s⁻²). Only unit powers up to +/-7 are supported: id est m² or m⁻² are supported but m⁸ is not.

Tuple Fields§

§0: f32

Implementations§

source§

impl<const U: i32> Quantity<U>

source

pub const ZERO: Self = _

source

pub const ONE: Self = _

source

pub const fn new_unchecked(value: f32) -> Self

Creates a new quantity without checking the value.

It is expected that the value is not a NaN. If NaN is given, the type might behave strangely or panic during some of the operations.

source

pub fn new(value: f32) -> Self

Crates a new quantity.

§Panics

Panics if value is NaN.

source

pub fn abs(&self) -> Self

Returns a new quantity with absolute value of self.

source

pub const fn inner(&self) -> f32

source§

impl Quantity<DIMENSIONLESS>

source

pub const FRAC_PI_2: Self = _

The angle equal to π/2.

source

pub fn normalized(&self) -> Self

Returns a new angle normalized to a values between 0.0 (inclusive) and the full circle constant τ (exclusive).

Trait Implementations§

source§

impl<const U: i32> Add for Quantity<U>

§

type Output = Quantity<U>

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
source§

impl<const U: i32> AddAssign for Quantity<U>

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl<const U: i32> Clone for Quantity<U>

source§

fn clone(&self) -> Quantity<U>

Returns a copy 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<const U: i32> Debug for Quantity<U>

source§

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

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

impl<const U: i32> Div<f32> for Quantity<U>

§

type Output = Quantity<U>

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> Self

Performs the / operation. Read more
source§

impl<const U: i32> DivAssign<f32> for Quantity<U>

source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
source§

impl<const U: i32> From<Quantity<U>> for f32

source§

fn from(quantity: Quantity<U>) -> f32

Converts to this type from the input type.
source§

impl Mul<Quantity<{ -$units }>> for Quantity<PIXEL>

§

type Output = f32

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Quantity<{ _ }>) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Quantity<{ -$units }>> for Quantity<SECOND>

§

type Output = f32

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Quantity<{ _ }>) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Quantity<PIXEL>> for Quantity<{ _ }>

§

type Output = f32

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Quantity<PIXEL>) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Quantity<SECOND>> for Quantity<{ _ }>

§

type Output = f32

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Quantity<SECOND>) -> Self::Output

Performs the * operation. Read more
source§

impl<const U: i32> Mul<Quantity<U>> for f32

§

type Output = Quantity<U>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Quantity<U>) -> Quantity<U>

Performs the * operation. Read more
source§

impl<const U: i32> Mul<f32> for Quantity<U>

§

type Output = Quantity<U>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f32) -> Self

Performs the * operation. Read more
source§

impl<const U: i32> MulAssign<f32> for Quantity<U>

source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
source§

impl<const U: i32> Neg for Quantity<U>

§

type Output = Quantity<U>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl<const U: i32> Ord for Quantity<U>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<const U: i32> PartialEq for Quantity<U>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const U: i32> PartialOrd for Quantity<U>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<const U: i32> Sub for Quantity<U>

§

type Output = Quantity<U>

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
source§

impl<const U: i32> SubAssign for Quantity<U>

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl<const U: i32> TryFrom<f32> for Quantity<U>

§

type Error = QuantityValueError

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

fn try_from(value: f32) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<const U: i32> Copy for Quantity<U>

source§

impl<const U: i32> Eq for Quantity<U>

Auto Trait Implementations§

§

impl<const U: i32> Freeze for Quantity<U>

§

impl<const U: i32> RefUnwindSafe for Quantity<U>

§

impl<const U: i32> Send for Quantity<U>

§

impl<const U: i32> Sync for Quantity<U>

§

impl<const U: i32> Unpin for Quantity<U>

§

impl<const U: i32> UnwindSafe for Quantity<U>

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> 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<T> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.