Struct const_decimal::Decimal
source · #[repr(transparent)]pub struct Decimal<I, const D: u8>(pub I);Tuple Fields§
§0: IImplementations§
source§impl<I, const D: u8> Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> Decimal<I, D>where
I: ScaledInteger<D>,
source§impl<I, const D: u8> Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> Decimal<I, D>where
I: ScaledInteger<D>,
pub const ZERO: Decimal<I, D> = _
pub const ONE: Decimal<I, D> = _
pub const TWO: Decimal<I, D> = _
pub const DECIMALS: u8 = D
pub const SCALING_FACTOR: I = I::SCALING_FACTOR
pub fn min() -> Self
pub fn max() -> Self
sourcepub fn from_scaled(integer: I, scale: u8) -> Self
pub fn from_scaled(integer: I, scale: u8) -> Self
Losslessly converts a scaled integer to this type.
§Panics
Panics if the integer cannot be represented without precision loss/overflow.
§Examples
use const_decimal::Decimal;
let five = Decimal::<u64, 3>::from_scaled(5, 0);
assert_eq!(five, Decimal::TWO + Decimal::TWO + Decimal::ONE);
assert_eq!(five.0, 5000);pub fn is_zero(&self) -> bool
Trait Implementations§
source§impl<I, const D: u8> AddAssign for Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> AddAssign for Decimal<I, D>where
I: ScaledInteger<D>,
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moresource§impl<I, const D: u8> DivAssign for Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> DivAssign for Decimal<I, D>where
I: ScaledInteger<D>,
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/= operation. Read moresource§impl<I, const D: u8> MulAssign for Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> MulAssign for Decimal<I, D>where
I: ScaledInteger<D>,
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moresource§impl<I: Ord, const D: u8> Ord for Decimal<I, D>
impl<I: Ord, const D: u8> Ord for Decimal<I, D>
1.21.0 · 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
source§impl<I: PartialOrd, const D: u8> PartialOrd for Decimal<I, D>
impl<I: PartialOrd, const D: u8> PartialOrd for Decimal<I, D>
source§impl<I, const D: u8> SubAssign for Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> SubAssign for Decimal<I, D>where
I: ScaledInteger<D>,
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreimpl<I: Copy, const D: u8> Copy for Decimal<I, D>
impl<I: Eq, const D: u8> Eq for Decimal<I, D>
impl<I, const D: u8> StructuralPartialEq for Decimal<I, D>
Auto Trait Implementations§
impl<I, const D: u8> Freeze for Decimal<I, D>where
I: Freeze,
impl<I, const D: u8> RefUnwindSafe for Decimal<I, D>where
I: RefUnwindSafe,
impl<I, const D: u8> Send for Decimal<I, D>where
I: Send,
impl<I, const D: u8> Sync for Decimal<I, D>where
I: Sync,
impl<I, const D: u8> Unpin for Decimal<I, D>where
I: Unpin,
impl<I, const D: u8> UnwindSafe for Decimal<I, D>where
I: 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: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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)