Struct uy::Quantity

source ·
#[repr(transparent)]
pub struct Quantity<T, U: Unit> { /* private fields */ }
Expand description

A physical quantity with a defined unit.

Implementations§

source§

impl<T, U: Unit> Quantity<T, U>

source

pub fn new(val: T) -> Self

Create a quantity from a value.

source

pub fn convert<Y: UnitConvert<T, U>>(self) -> Quantity<T, Y>

Convert between quantities with different units or the same units with different scales.

let a: Quantity<i32, si::m> = Quantity::new(3);
let b: Quantity<i32, si::milli<si::m>> = a.convert();
assert_eq!(*b, 3000);

Trait Implementations§

source§

impl<T, U: Unit> Add<Quantity<T, U>> for Quantity<T, U>where T: Add<Output = T>,

§

type Output = Quantity<T, U>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T: Clone, U: Unit> Clone for Quantity<T, U>

source§

fn clone(&self) -> Self

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<T: Debug, U: Debug + Unit> Debug for Quantity<T, U>

source§

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

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

impl<T, U: Unit> Deref for Quantity<T, U>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T, U: Unit> DerefMut for Quantity<T, U>

source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
source§

impl<T, U1, U2: Unit> Div<Quantity<T, U2>> for Quantity<T, U1>where T: Div<Output = T>, U1: Div<U2> + Unit, <U1 as Div<U2>>::Output: Unit,

§

type Output = Quantity<T, <U1 as Div<U2>>::Output>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Quantity<T, U2>) -> Self::Output

Performs the / operation. Read more
source§

impl<T, U: Unit> From<T> for Quantity<T, U>

source§

fn from(val: T) -> Self

Converts to this type from the input type.
source§

impl<T: Hash, U: Unit> Hash for Quantity<T, U>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, U1, U2: Unit> Mul<Quantity<T, U2>> for Quantity<T, U1>where T: Mul<Output = T>, U1: Mul<U2> + Unit, <U1 as Mul<U2>>::Output: Unit,

§

type Output = Quantity<T, <U1 as Mul<U2>>::Output>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T: Ord, U: Unit> Ord for Quantity<T, 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) -> Selfwhere Self: Sized,

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

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

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

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

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

impl<T: PartialEq, U: Unit> PartialEq<Quantity<T, U>> for Quantity<T, 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<T: PartialOrd, U: Unit> PartialOrd<Quantity<T, U>> for Quantity<T, 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<T, U: Unit> Sub<Quantity<T, U>> for Quantity<T, U>where T: Sub<Output = T>,

§

type Output = Quantity<T, U>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T: Copy, U: Unit> Copy for Quantity<T, U>

source§

impl<T: Eq, U: Unit> Eq for Quantity<T, U>

Auto Trait Implementations§

§

impl<T, U> RefUnwindSafe for Quantity<T, U>where T: RefUnwindSafe, U: RefUnwindSafe,

§

impl<T, U> Send for Quantity<T, U>where T: Send, U: Send,

§

impl<T, U> Sync for Quantity<T, U>where T: Sync, U: Sync,

§

impl<T, U> Unpin for Quantity<T, U>where T: Unpin, U: Unpin,

§

impl<T, U> UnwindSafe for Quantity<T, U>where T: UnwindSafe, U: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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 Twhere 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 Twhere 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.