pub struct UnitRegistry { /* private fields */ }
Expand description
Registry for unit definitions and conversions
Implementations§
Source§impl UnitRegistry
impl UnitRegistry
Sourcepub fn register_unit(&mut self, unit: UnitDefinition)
pub fn register_unit(&mut self, unit: UnitDefinition)
Register a unit definition
Sourcepub fn register_alias(&mut self, alias: String, canonical: String)
pub fn register_alias(&mut self, alias: String, canonical: String)
Register an alias for a unit
Sourcepub fn get_unit(&self, symbol: &str) -> Option<&UnitDefinition>
pub fn get_unit(&self, symbol: &str) -> Option<&UnitDefinition>
Get a unit definition by symbol or alias
Sourcepub fn are_compatible(&self, unit1: &str, unit2: &str) -> bool
pub fn are_compatible(&self, unit1: &str, unit2: &str) -> bool
Check if two units are compatible (same dimension)
Sourcepub fn convert(
&self,
value: f64,
from_unit: &str,
tounit: &str,
) -> CoreResult<f64>
pub fn convert( &self, value: f64, from_unit: &str, tounit: &str, ) -> CoreResult<f64>
Convert a value from one unit to another
Sourcepub fn convert_value<T>(
&self,
value: &UnitValue<T>,
tounit: &str,
) -> CoreResult<UnitValue<T>>
pub fn convert_value<T>( &self, value: &UnitValue<T>, tounit: &str, ) -> CoreResult<UnitValue<T>>
Convert a UnitValue to a different unit
Sourcepub fn get_units_for_dimension(
&self,
dimension: &Dimension,
) -> Vec<&UnitDefinition>
pub fn get_units_for_dimension( &self, dimension: &Dimension, ) -> Vec<&UnitDefinition>
Get all units for a given dimension
Sourcepub fn get_units_for_system(&self, system: &UnitSystem) -> Vec<&UnitDefinition>
pub fn get_units_for_system(&self, system: &UnitSystem) -> Vec<&UnitDefinition>
Get all units in a given system
Sourcepub fn list_units(&self) -> Vec<&UnitDefinition>
pub fn list_units(&self) -> Vec<&UnitDefinition>
List all registered units
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UnitRegistry
impl RefUnwindSafe for UnitRegistry
impl Send for UnitRegistry
impl Sync for UnitRegistry
impl Unpin for UnitRegistry
impl UnwindSafe for UnitRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more