pub struct Dec { /* private fields */ }Expand description
An exact decimal, units / 10^scale, for every amount the venue prices
in. The venue sends and takes these as strings, and a float between the
two would change the figure that gets signed.
Implementations§
Source§impl Dec
impl Dec
pub const ZERO: Dec
pub const ONE: Dec
Sourcepub const fn new(units: i128, scale: u32) -> Option<Dec>
pub const fn new(units: i128, scale: u32) -> Option<Dec>
units / 10^scale. A scale past MAX_SCALE is refused.
pub const fn from_int(whole: i64) -> Dec
Sourcepub fn parse(text: &str) -> Result<Dec, BadDec>
pub fn parse(text: &str) -> Result<Dec, BadDec>
Reads what the venue writes: an optional sign, digits, and at most one point. No exponent, since the venue never sends one.
pub const fn is_zero(self) -> bool
pub const fn is_negative(self) -> bool
pub const fn is_positive(self) -> bool
pub fn is_integer(self) -> bool
pub const fn abs(self) -> Dec
pub const fn negate(self) -> Dec
Sourcepub fn units_at(self, places: u32, round: Round) -> Option<i128>
pub fn units_at(self, places: u32, round: Round) -> Option<i128>
The value as a count of 10^-places, rounded as asked. An integer
amount on a chain (USDC in millionths, say) comes out of here.
Sourcepub fn sig_places(self, figures: u32) -> u32
pub fn sig_places(self, figures: u32) -> u32
The places figures significant digits reach for this value: 2 for
123.456 at five figures, 6 for 0.01234567; 0 when they end in the
whole part (123456.7).
Sourcepub fn round_sig(self, figures: u32, round: Round) -> Dec
pub fn round_sig(self, figures: u32, round: Round) -> Dec
Kept to at most figures significant digits. Digits dropped before the
point become zeros, so 123456.7 to five figures is 123450.
pub fn checked_add(self, other: Dec) -> Option<Dec>
pub fn checked_sub(self, other: Dec) -> Option<Dec>
Sourcepub fn checked_sum(figures: impl IntoIterator<Item = Dec>) -> Option<Dec>
pub fn checked_sum(figures: impl IntoIterator<Item = Dec>) -> Option<Dec>
Every figure added exactly, in order; zero for none. None once a
running total passes what a Dec holds.
Sourcepub fn checked_mul(self, other: Dec) -> Option<Dec>
pub fn checked_mul(self, other: Dec) -> Option<Dec>
Exact while the product fits eighteen places; past that, the nearest.
Trait Implementations§
impl Copy for Dec
Source§impl<'de> Deserialize<'de> for Dec
From the venue’s decimal strings, or a JSON integer. A JSON fraction is
refused: it has already been through a float.
impl<'de> Deserialize<'de> for Dec
From the venue’s decimal strings, or a JSON integer. A JSON fraction is refused: it has already been through a float.
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Dec
Source§impl Ord for Dec
impl Ord for Dec
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Auto Trait Implementations§
impl Freeze for Dec
impl RefUnwindSafe for Dec
impl Send for Dec
impl Sync for Dec
impl Unpin for Dec
impl UnsafeUnpin for Dec
impl UnwindSafe for Dec
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.