Struct const_units::DynQuantity
source · pub struct DynQuantity<V>(pub V, pub SI);Expand description
A value with dimensionality, checked at runtime
Tuple Fields§
§0: V§1: SIImplementations§
source§impl<V> DynQuantity<V>
impl<V> DynQuantity<V>
sourcepub fn powi(self, exp: i32) -> DynQuantity<V::Output>
pub fn powi(self, exp: i32) -> DynQuantity<V::Output>
Take the power to an integer
assert_eq!(DynQuantity(2., meter).powi(2), DynQuantity(4., meter.powi(2)));sourcepub fn powf(self, exp: (i32, u32)) -> DynQuantity<V::Output>
pub fn powf(self, exp: (i32, u32)) -> DynQuantity<V::Output>
Take the power to a fraction
assert_eq!(DynQuantity(4., meter).powf((1, 2)), DynQuantity(2., meter.powf((1, 2))));sourcepub fn convert_to(
self,
new_units: SI
) -> Result<DynQuantity<V>, InconsistentUnits>
pub fn convert_to( self, new_units: SI ) -> Result<DynQuantity<V>, InconsistentUnits>
Convert a DynQuantity to a different set of units
Okay
// Converting minutes to seconds
assert_eq!(DynQuantity(1., minute).convert_to(second), Ok(DynQuantity(60., second)));
// Can't convert meters to seconds
assert!(DynQuantity(1., meter).convert_to(second).is_err())sourcepub fn checked_add<R>(
self,
rhs: DynQuantity<R>
) -> Result<DynQuantity<<V as Add<R>>::Output>, InconsistentUnits>where
V: Add<R>,
pub fn checked_add<R>(
self,
rhs: DynQuantity<R>
) -> Result<DynQuantity<<V as Add<R>>::Output>, InconsistentUnits>where
V: Add<R>,
Add two DynQuantitys. Will return an error if they have different units.
sourcepub fn checked_sub<R>(
self,
rhs: DynQuantity<R>
) -> Result<DynQuantity<<V as Sub<R>>::Output>, InconsistentUnits>where
V: Sub<R>,
pub fn checked_sub<R>(
self,
rhs: DynQuantity<R>
) -> Result<DynQuantity<<V as Sub<R>>::Output>, InconsistentUnits>where
V: Sub<R>,
Subtract two DynQuantitys. Will return an error if they have different units.
source§impl<V: Display> DynQuantity<V>
impl<V: Display> DynQuantity<V>
sourcepub fn write_as(
&self,
units: &'static str,
f: &mut Formatter<'_>
) -> Result<(), Error>
pub fn write_as( &self, units: &'static str, f: &mut Formatter<'_> ) -> Result<(), Error>
Write the quantity to a formatter using the given units. Must be parseable by crate::si. Will return core::fmt::Error if units couldn’t be parsed or if they aren’t equal to the DynQuantity’s units.
For copy/paste purposes: ⋅
sourcepub fn format_as(
&self,
units: &'static str
) -> Result<String, FormatAsError<'_>>
pub fn format_as( &self, units: &'static str ) -> Result<String, FormatAsError<'_>>
Format the quantity using the given units. Must be parseable by crate::si.
Multiplication symbol for copy/paste purposes: ⋅
Okay:
assert_eq!(DynQuantity(1., newton).format_as("N"), Ok("1 N".to_owned()));
assert!(DynQuantity(1., newton).format_as("K").is_err());Trait Implementations§
source§impl<R, T: Add<R>> Add<DynQuantity<R>> for DynQuantity<T>
impl<R, T: Add<R>> Add<DynQuantity<R>> for DynQuantity<T>
source§impl<R, T: AddAssign<R>> AddAssign<DynQuantity<R>> for DynQuantity<T>
impl<R, T: AddAssign<R>> AddAssign<DynQuantity<R>> for DynQuantity<T>
Units must be the same for addition
source§fn add_assign(&mut self, rhs: DynQuantity<R>)
fn add_assign(&mut self, rhs: DynQuantity<R>)
+= operation. Read moresource§impl<V: Clone> Clone for DynQuantity<V>
impl<V: Clone> Clone for DynQuantity<V>
source§fn clone(&self) -> DynQuantity<V>
fn clone(&self) -> DynQuantity<V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<V: Debug> Debug for DynQuantity<V>
impl<V: Debug> Debug for DynQuantity<V>
source§impl<V: Display> Display for DynQuantity<V>
impl<V: Display> Display for DynQuantity<V>
source§impl<R, T: Div<R>> Div<DynQuantity<R>> for DynQuantity<T>
impl<R, T: Div<R>> Div<DynQuantity<R>> for DynQuantity<T>
source§impl<R, T: DivAssign<R>> DivAssign<DynQuantity<R>> for DynQuantity<T>
impl<R, T: DivAssign<R>> DivAssign<DynQuantity<R>> for DynQuantity<T>
source§fn div_assign(&mut self, rhs: DynQuantity<R>)
fn div_assign(&mut self, rhs: DynQuantity<R>)
/= operation. Read moresource§impl<R, T: Mul<R>> Mul<DynQuantity<R>> for DynQuantity<T>
impl<R, T: Mul<R>> Mul<DynQuantity<R>> for DynQuantity<T>
source§impl<R, T: MulAssign<R>> MulAssign<DynQuantity<R>> for DynQuantity<T>
impl<R, T: MulAssign<R>> MulAssign<DynQuantity<R>> for DynQuantity<T>
source§fn mul_assign(&mut self, rhs: DynQuantity<R>)
fn mul_assign(&mut self, rhs: DynQuantity<R>)
*= operation. Read moresource§impl<V: PartialEq> PartialEq for DynQuantity<V>
impl<V: PartialEq> PartialEq for DynQuantity<V>
source§fn eq(&self, other: &DynQuantity<V>) -> bool
fn eq(&self, other: &DynQuantity<V>) -> bool
self and other values to be equal, and is used
by ==.source§impl<V: PartialOrd> PartialOrd for DynQuantity<V>
impl<V: PartialOrd> PartialOrd for DynQuantity<V>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<R, T: Sub<R>> Sub<DynQuantity<R>> for DynQuantity<T>
impl<R, T: Sub<R>> Sub<DynQuantity<R>> for DynQuantity<T>
Units must be the same for addition
source§impl<R, T: SubAssign<R>> SubAssign<DynQuantity<R>> for DynQuantity<T>
impl<R, T: SubAssign<R>> SubAssign<DynQuantity<R>> for DynQuantity<T>
Units must be the same for addition
source§fn sub_assign(&mut self, rhs: DynQuantity<R>)
fn sub_assign(&mut self, rhs: DynQuantity<R>)
-= operation. Read more