Skip to main content

Unit

Struct Unit 

Source
pub struct Unit { /* private fields */ }
Expand description

Represents a dimensional quantity: a numeric factor paired with zero or more base dimensions.

Implementations§

Source§

impl Unit

Source

pub fn new() -> Self

Creates a freshly initialised unit with factor 1.0 and no dimensions.

Source

pub fn parse(input: &str) -> Result<Self>

Parses a GNU units expression string and returns the resulting Unit.

Source

pub fn factor(&self) -> f64

Returns the numeric factor of the unit.

Source

pub fn base_units(&self) -> String

Returns the base dimensions as a human-readable string.

Source

pub fn multiply(&mut self, rhs: Unit) -> Result<()>

Multiplies self by rhs in place.

Source

pub fn divide(&mut self, rhs: Unit) -> Result<()>

Divides self by rhs in place.

Source

pub fn add(&mut self, rhs: Unit) -> Result<()>

Adds rhs to self in place.

Source

pub fn invert(&mut self)

Inverts self in place (reciprocal).

Source

pub fn pow(&mut self, power: i32) -> Result<()>

Raises self to a non-negative integer power in place.

Source

pub fn root(&mut self, n: i32) -> Result<()>

Takes the n-th root of self in place.

Source

pub fn to_number(&self) -> Result<f64>

Converts a dimensionless unit to its numeric value.

Source

pub fn convert_to(self, to: Unit) -> Result<f64>

Converts self into the unit expressed by to, returning the numeric conversion factor.

Source

pub fn is_conformable(&self, other: &Unit) -> bool

Returns true when self and other have the same base dimensions.

Trait Implementations§

Source§

impl Clone for Unit

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Unit

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Unit

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Freeze for Unit

§

impl RefUnwindSafe for Unit

§

impl Send for Unit

§

impl Sync for Unit

§

impl Unpin for Unit

§

impl UnsafeUnpin for Unit

§

impl UnwindSafe for Unit

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

Source§

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.