pub struct Decimal(/* private fields */);Expand description
A Decimal in thousandths: at most 12 integer and 3 fractional digits.
§Examples
use parse_net::sfv::{self, BareItem, Decimal};
assert_eq!(sfv::parse_item(b"-1.5")?.bare, BareItem::Decimal(Decimal::from_thousandths(-1500)?));
assert!(Decimal::from_thousandths(1_000_000_000_000_000).is_err());Implementations§
Source§impl Decimal
impl Decimal
Sourcepub const fn from_thousandths(t: i64) -> Result<Self, ParseError>
pub const fn from_thousandths(t: i64) -> Result<Self, ParseError>
The decimal t / 1000.
§Errors
ErrorKind::OutOfRange beyond 12 integer digits.
§Examples
use parse_net::sfv::Decimal;
assert_eq!(Decimal::from_thousandths(1500)?.thousandths(), 1500);
assert!(Decimal::from_thousandths(1_000_000_000_000_000).is_err());Sourcepub const fn thousandths(self) -> i64
pub const fn thousandths(self) -> i64
The value in thousandths.
§Examples
use parse_net::sfv::{self, BareItem};
let BareItem::Decimal(d) = sfv::parse_item(b"2.25")?.bare else { unreachable!() };
assert_eq!(d.thousandths(), 2250);Trait Implementations§
impl Copy for Decimal
impl Eq for Decimal
Source§impl Ord for Decimal
impl Ord for Decimal
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Decimal
impl PartialOrd for Decimal
impl StructuralPartialEq for Decimal
Auto Trait Implementations§
impl Freeze for Decimal
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnsafeUnpin for Decimal
impl UnwindSafe for Decimal
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