pub struct Quantity { /* private fields */ }Expand description
Represents a physical quantity consisting of a scalar value and a Dimension.
§Example
use dimensional_analyser::{quantity::Quantity, dimensions::le_systeme_international_d_unites::{JOULE, base_units::{KILOGRAM, METER, SECOND}}};
let mass = Quantity::new(5, &KILOGRAM);
let velocity = Quantity::new(10, &(&*METER / &*SECOND));
let kinetic_energy = (&mass * &velocity.power(2)) / 2;
assert_eq!(kinetic_energy, Quantity::new(250, &JOULE));Implementations§
Source§impl Quantity
impl Quantity
Sourcepub fn power<T: Into<f64> + Copy>(&self, exponent: T) -> Self
pub fn power<T: Into<f64> + Copy>(&self, exponent: T) -> Self
Raises the quantity to the specified power.
Sourcepub fn convert_to(
&self,
other: &Dimension,
) -> Result<Self, UnconvertableQuantityError>
pub fn convert_to( &self, other: &Dimension, ) -> Result<Self, UnconvertableQuantityError>
Attempts to convert the quantity to another compatible dimension.
§Errors
UnconvertableQuantityError when the base Quantity can’t be converted to the target Dimension
§Example
use dimensional_analyser::{dimension::Prefix::Centi, quantity::Quantity, dimensions::le_systeme_international_d_unites::base_units::METER};
let one_square_centimeter = Quantity::new(1, &METER.prefix(&Centi).square());
let area_in_square_meters = one_square_centimeter.convert_to(&METER.square()).unwrap();
assert_eq!(area_in_square_meters, Quantity::new(0.0001, &METER.square()));Sourcepub fn get_equality_with(&self, other: &Self) -> Equality
pub fn get_equality_with(&self, other: &Self) -> Equality
Returns the relationship between both Quantity’s.
§Panics
Not enough data is known after converting self to the other.dimension so an expect is used
§Example
use dimensional_analyser::{quantity::Quantity, dimensions::le_systeme_international_d_unites::{MINUTE, base_units::SECOND}, quantity::Equality};
let one_minute = Quantity::new(1, &MINUTE);
let sixty_seconds = Quantity::new(60, &SECOND);
match one_minute.get_equality_with(&sixty_seconds) {
Equality::ScalarMultiple(factor) => assert_eq!(factor, 60.0),
_ => panic!("1 min and 60 s should be scalar multiples"),
}Sourcepub fn show_comparizon_results_with(&self, other: &Self)
pub fn show_comparizon_results_with(&self, other: &Self)
Helper function to print how both Quantity’s are related.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Quantity
impl RefUnwindSafe for Quantity
impl Send for Quantity
impl Sync for Quantity
impl Unpin for Quantity
impl UnwindSafe for Quantity
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