pub struct Dim(/* private fields */);Expand description
A dimension: integer exponents of kilogram, metre, second, ampere, kelvin, mole and candela, in that order.
The mass base is the kilogram, not the gram. Plane angle is dimensionless (see ADR-007).
All arithmetic is checked: exponent overflow is reported as Error::Overflow.
§Examples
use dimvexa_core::Dim;
let velocity = Dim::M.checked_sub(Dim::S)?;
assert_eq!(velocity.exponents(), [0, 1, -1, 0, 0, 0, 0]);
let accel = velocity.checked_sub(Dim::S)?;
let force = Dim::KG.checked_add(accel)?;
assert_eq!(force.to_string(), "kg m s^-2");Implementations§
Source§impl Dim
impl Dim
Sourcepub const fn new(exponents: [i8; 7]) -> Self
pub const fn new(exponents: [i8; 7]) -> Self
Builds a dimension from exponents of [kg, m, s, A, K, mol, cd].
Sourcepub fn is_dimensionless(self) -> bool
pub fn is_dimensionless(self) -> bool
True if every exponent is zero.
Sourcepub fn checked_add(self, other: Self) -> Result<Self>
pub fn checked_add(self, other: Self) -> Result<Self>
Sourcepub fn checked_sub(self, other: Self) -> Result<Self>
pub fn checked_sub(self, other: Self) -> Result<Self>
Dimension of a quotient: exponents subtract.
§Errors
Error::Overflow if an exponent leaves the i8 range.
Sourcepub fn checked_scale(self, n: i32) -> Result<Self>
pub fn checked_scale(self, n: i32) -> Result<Self>
Dimension of a power: every exponent is multiplied by n.
§Errors
Error::Overflow if an exponent leaves the i8 range.
Sourcepub fn checked_neg(self) -> Result<Self>
pub fn checked_neg(self) -> Result<Self>
Dimension of the reciprocal: every exponent is negated.
§Errors
Error::Overflow if an exponent is i8::MIN.
Trait Implementations§
impl Copy for Dim
impl Eq for Dim
impl StructuralPartialEq for Dim
Auto Trait Implementations§
impl Forget for Dim
impl Freeze for Dim
impl RefUnwindSafe for Dim
impl Send for Dim
impl Sync for Dim
impl Unpin for Dim
impl UnsafeUnpin for Dim
impl UnwindSafe for Dim
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