pub struct Price(/* private fields */);Expand description
Domain value type representing a price.
Implementations§
Source§impl Price
impl Price
Sourcepub fn try_new(value: u128) -> Result<Self, PriceLevelError>
pub fn try_new(value: u128) -> Result<Self, PriceLevelError>
Creates a validated price from a raw integer value.
§Errors
Returns PriceLevelError::InvalidFieldValue if value ever fails the
price invariant. Every u128 is currently a valid price, so this
constructor is presently infallible; the Result is part of its stable
contract so validation can be tightened without a breaking change.
Sourcepub fn from_f64(value: f64) -> Result<Self, PriceLevelError>
pub fn from_f64(value: f64) -> Result<Self, PriceLevelError>
Creates a price from an f64 value (rounded to the nearest integer).
§Errors
Returns PriceLevelError::InvalidOperation if value is not finite
(NaN or infinite), is negative, or (after rounding) does not fit in a
u128. The range check is explicit because an f64-to-u128 as cast
saturates rather than failing, which would silently clamp out-of-range
input to u128::MAX.
Sourcepub fn to_f64_lossy(self) -> f64
pub fn to_f64_lossy(self) -> f64
Converts the price to f64 with potential precision loss.