#[non_exhaustive]pub struct Unit { /* private fields */ }Expand description
A unit of measurement that includes a power.
Implementations§
Source§impl Unit
impl Unit
Sourcepub fn new(quantity: impl Into<Base>) -> Self
pub fn new(quantity: impl Into<Base>) -> Self
Creates a new unit with the given quantity, with power 1.
Sourcepub fn with_power(quantity: impl Into<Base>, power: i8) -> Self
pub fn with_power(quantity: impl Into<Base>, power: i8) -> Self
Creates a new unit with the given quantity and power.
Sourcepub fn conversion_factor(&self, target: Unit) -> Result<f64, ConversionError>
pub fn conversion_factor(&self, target: Unit) -> Result<f64, ConversionError>
If this unit can be converted to the target unit, returns the conversion factor between them.
Trait Implementations§
Source§impl From<Unit> for CompoundUnit
impl From<Unit> for CompoundUnit
Source§impl FromStr for Unit
Try a to convert a string to a Unit.
impl FromStr for Unit
Try a to convert a string to a Unit.
The string should be in the format <base>[^<power>], where <quantity> is the
abbreviation of the quantity (see Base), and <power> is a signed integer representing the
power of the unit. If <power> is not specified, it is assumed to be 1.
Source§impl TryFrom<&str> for Unit
Try a to convert a string to a Unit.
impl TryFrom<&str> for Unit
Try a to convert a string to a Unit.
The string should be in the format <quantity>[^<power>], where <quantity> is the
abbreviation of the quantity (see Base), and <power> is the power of the unit. If
<power> is not specified, it is assumed to be 1.