pub struct Quantity<U: QuantityUnit> { /* private fields */ }Expand description
A fixed-point decimal value with a unit, constrained by the QuantityUnit
marker U. Encodes to the rich SchemaValue::Quantity.
Clone/Debug/PartialEq/Eq are implemented by hand so the marker type
U itself does not need to implement them.
Implementations§
Source§impl<U: QuantityUnit> Quantity<U>
impl<U: QuantityUnit> Quantity<U>
Sourcepub fn new(
mantissa: i64,
scale: i32,
unit: impl Into<String>,
) -> Result<Self, FromSchemaError>
pub fn new( mantissa: i64, scale: i32, unit: impl Into<String>, ) -> Result<Self, FromSchemaError>
Constructs a quantity, validating the unit against U.
Sourcepub fn from_quantity_value(
value: QuantityValue,
) -> Result<Self, FromSchemaError>
pub fn from_quantity_value( value: QuantityValue, ) -> Result<Self, FromSchemaError>
Wraps a QuantityValue, validating its unit against U.
pub fn as_quantity_value(&self) -> &QuantityValue
pub fn into_quantity_value(self) -> QuantityValue
Trait Implementations§
Source§impl<U: QuantityUnit> Clone for Quantity<U>
impl<U: QuantityUnit> Clone for Quantity<U>
Source§impl<U: QuantityUnit> Debug for Quantity<U>
impl<U: QuantityUnit> Debug for Quantity<U>
impl<U: QuantityUnit> Eq for Quantity<U>
Source§impl<U: QuantityUnit> FromSchema for Quantity<U>
impl<U: QuantityUnit> FromSchema for Quantity<U>
fn from_value(v: &SchemaValue) -> Result<Self, FromSchemaError>
Source§impl<U: QuantityUnit> IntoSchema for Quantity<U>
impl<U: QuantityUnit> IntoSchema for Quantity<U>
fn type_id() -> TypeId
fn register_in(_b: &mut SchemaBuilder) -> SchemaType
fn to_value(&self) -> SchemaValue
Auto Trait Implementations§
impl<U> Freeze for Quantity<U>where
PhantomData<U>: Freeze,
impl<U> RefUnwindSafe for Quantity<U>where
PhantomData<U>: RefUnwindSafe,
impl<U> Send for Quantity<U>where
PhantomData<U>: Send,
impl<U> Sync for Quantity<U>where
PhantomData<U>: Sync,
impl<U> Unpin for Quantity<U>where
PhantomData<U>: Unpin,
impl<U> UnsafeUnpin for Quantity<U>where
PhantomData<U>: UnsafeUnpin,
impl<U> UnwindSafe for Quantity<U>where
PhantomData<U>: UnwindSafe,
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