pub trait BasicDecimal: PartialOrd + Ord + PartialEq + Eq {
    const BIT_WIDTH: usize;

    fn new(precision: usize, scale: usize, bytes: &[u8]) -> Self;
    fn raw_value(&self) -> &[u8]Notable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8];
    fn precision(&self) -> usize;
    fn scale(&self) -> usize;

    fn try_new_from_bytes(
        precision: usize,
        scale: usize,
        bytes: &[u8]
    ) -> Result<Self>
    where
        Self: Sized
, { ... } fn to_string(&self) -> String { ... } }

Required Associated Constants

The bit-width of the internal representation.

Required Methods

Creates a decimal value from precision, scale, and bytes.

Safety: This method doesn’t check if the length of bytes is compatible with this decimal. Use try_new_from_bytes for safe constructor.

Returns the raw bytes of the integer representation of the decimal.

Returns the precision of the decimal.

Returns the scale of the decimal.

Provided Methods

Tries to create a decimal value from precision, scale and bytes. If the length of bytes isn’t same as the bit width of this decimal, returning an error. The bytes should be stored in little-endian order.

Safety: This method doesn’t validate if the decimal value represented by the bytes can be fitted into the specified precision.

Returns the string representation of the decimal. If the string representation cannot be fitted with the precision of the decimal, the string will be truncated.

Implementors