pub struct Rate<A, B>(/* private fields */);Expand description
A rate representing A / B.
Implementations§
source§impl<A, B> Rate<A, B>
impl<A, B> Rate<A, B>
sourcepub fn new(rate: Decimal) -> Option<Self>
pub fn new(rate: Decimal) -> Option<Self>
Create a new rate from a decimal. Returns None if the rate is zero.
sourcepub unsafe fn new_unchecked(rate: Decimal) -> Self
pub unsafe fn new_unchecked(rate: Decimal) -> Self
Create a new rate from a decimal without checking if it is zero.
§Safety
The user ensures that the rate is non-zero. Violating this contract will lead to
pub fn rate(&self) -> Decimal
pub fn inv(&self) -> Rate<B, A>
sourcepub fn add_decimal(&self, decimal: Decimal) -> StdResult<Rate<A, B>>
pub fn add_decimal(&self, decimal: Decimal) -> StdResult<Rate<A, B>>
Adds a Decimal value to this. This is useful for adding a directly calculated decimal to a typed rate.
sourcepub fn sub_decimal(&self, decimal: Decimal) -> StdResult<Rate<A, B>>
pub fn sub_decimal(&self, decimal: Decimal) -> StdResult<Rate<A, B>>
Subtracts a Decimal value from this. This is useful for subtracting a directly calculated decimal from a typed rate.
Trait Implementations§
source§impl<'de, A, B> Deserialize<'de> for Rate<A, B>
impl<'de, A, B> Deserialize<'de> for Rate<A, B>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<A: JsonSchema, B: JsonSchema> JsonSchema for Rate<A, B>
impl<A: JsonSchema, B: JsonSchema> JsonSchema for Rate<A, B>
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref keyword. Read moresource§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
source§impl<A: PartialEq, B: PartialEq> PartialEq for Rate<A, B>
impl<A: PartialEq, B: PartialEq> PartialEq for Rate<A, B>
impl<A: Copy, B: Copy> Copy for Rate<A, B>
impl<A: Eq, B: Eq> Eq for Rate<A, B>
impl<A, B> StructuralPartialEq for Rate<A, B>
Auto Trait Implementations§
impl<A, B> Freeze for Rate<A, B>
impl<A, B> RefUnwindSafe for Rate<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for Rate<A, B>
impl<A, B> Sync for Rate<A, B>
impl<A, B> Unpin for Rate<A, B>
impl<A, B> UnwindSafe for Rate<A, B>where
A: UnwindSafe,
B: 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
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more