Struct const_units::SI
source · pub struct SI {
pub scale: (i128, u128),
pub s: (i32, u32),
pub m: (i32, u32),
pub kg: (i32, u32),
pub A: (i32, u32),
pub K: (i32, u32),
pub mol: (i32, u32),
pub cd: (i32, u32),
}Expand description
Represents SI units
Each field contains the exponent of the corresponding dimension. Exponents are fractions where the first element of the tuple is the numerator and the second is the denominator. Ensure the fractions are fully simplified if you’re creating an instance directly.
Fields§
§scale: (i128, u128)A scale factor - used for units that are constant multiples of other units; ie. minutes or kilometers
s: (i32, u32)Seconds
m: (i32, u32)Meters
kg: (i32, u32)Kilograms
A: (i32, u32)Amperes
K: (i32, u32)Kelvin
mol: (i32, u32)Moles
cd: (i32, u32)Candelas
Implementations§
source§impl SI
impl SI
sourcepub const fn scale_by(self, scale: (i128, u128)) -> Self
pub const fn scale_by(self, scale: (i128, u128)) -> Self
Multiply the scale factor by a given constant
assert_eq!(second.scale_by((60, 1)), minute)sourcepub const fn mul(self, rhs: Self) -> Self
pub const fn mul(self, rhs: Self) -> Self
Multiply SI units
assert_eq!(newton.mul(meter), joule)sourcepub const fn powi(self, v: i32) -> Self
pub const fn powi(self, v: i32) -> Self
Raise SI units to an integer power
assert_eq!(second.powi(-1), hertz);sourcepub const fn checked_powf(self, v: (i32, u32)) -> Option<Self>
pub const fn checked_powf(self, v: (i32, u32)) -> Option<Self>
A checked version of pow
assert_eq!(meter.powi(2).checked_powf((1, 2)), Some(meter));
assert_eq!(meter.scale_by((2, 1)).checked_powf((1, 2)), None);sourcepub const fn same_dimension(self, other: SI) -> bool
pub const fn same_dimension(self, other: SI) -> bool
Determine whether two units measure the same dimension
use const_units::si;
assert!(si("min").same_dimension(si("s")));
assert!(!si("cd").same_dimension(si("s")));Trait Implementations§
impl ConstParamTy for SI
impl Copy for SI
impl Eq for SI
impl StructuralEq for SI
impl StructuralPartialEq for SI
Auto Trait Implementations§
impl RefUnwindSafe for SI
impl Send for SI
impl Sync for SI
impl Unpin for SI
impl UnwindSafe for SI
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