pub struct Quantity(/* private fields */);Expand description
Implementations§
Source§impl Quantity
impl Quantity
Sourcepub fn checked_add(self, other: Quantity) -> Option<Quantity>
pub fn checked_add(self, other: Quantity) -> Option<Quantity>
Adds other to this quantity, returning None if the result overflows.
Sourcepub fn checked_sub(self, other: Quantity) -> Option<Quantity>
pub fn checked_sub(self, other: Quantity) -> Option<Quantity>
Subtracts other from self, returning None if the result would be negative or overflow.
Sourcepub fn abs(self) -> Quantity
pub fn abs(self) -> Quantity
Returns the absolute value of this quantity’s underlying decimal.
Quantity values are normally non-negative, but this is useful when
working with raw Decimal fields (e.g. from sub operations that yield
negative Decimals wrapped in Quantity(d) via internal code paths).
Sourcepub fn split(self, n: usize) -> Vec<Quantity>
pub fn split(self, n: usize) -> Vec<Quantity>
Splits this quantity into n equal parts, with the last absorbing any remainder.
Returns an empty vec if n is zero.
Guarantees that sum(result) == self.value().
Sourcepub fn proportion_of(self, total: Quantity) -> Option<Decimal>
pub fn proportion_of(self, total: Quantity) -> Option<Decimal>
Returns self / total as a proportion, or None if total is zero.
Useful for computing position weight within a portfolio.
Trait Implementations§
Source§impl Add for Quantity
Quantity + Quantity always yields a valid Quantity (sum of non-negatives is non-negative).
impl Add for Quantity
Quantity + Quantity always yields a valid Quantity (sum of non-negatives is non-negative).