Skip to main content

Fixed

Struct Fixed 

Source
pub struct Fixed { /* private fields */ }
Expand description

The value of an IDL fixed<digits, scale>: a decimal number with a sign, its digits and the number of them after the decimal point.

The value is kept as it was made, and fitted to the digits and scale of a fixed type when it is sent: digits after the scale are cut off, and an integer part that does not fit is DATA_CONVERSION. Values compare by their number, so 1.50 equals 1.5. Arithmetic is not provided.

Implementations§

Source§

impl Fixed

Source

pub fn from_digits(digits: &[u8], scale: u16, negative: bool) -> Option<Fixed>

The value with the digits digits (each 0 to 9, most significant first), scale of them after the decimal point. None if a digit is over 9 or there are fewer digits than scale.

Source

pub fn digits(&self) -> &[u8] ⓘ

The digits, most significant first, without leading zeros in the integer part.

Source

pub fn scale(&self) -> u16

How many of the digits are after the decimal point.

Source

pub fn is_negative(&self) -> bool

Whether the value is below zero.

Source

pub fn truncate(&self, scale: u16) -> Fixed

The value with at most scale digits after the decimal point, the others cut off.

Source

pub fn round(&self, scale: u16) -> Fixed

The value with at most scale digits after the decimal point, rounded half away from zero.

Source

pub fn to_digits(&self, digits: u16, scale: u16) -> Option<Vec<u8>>

The exactly digits digits of the value as a fixed<digits, scale>, digits after scale cut off; None if the integer part does not fit.

Trait Implementations§

Source§

impl Clone for Fixed

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fixed

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Fixed

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Fixed

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Writes the value with all its digits: -12.50, 0.5, 7.

Source§

impl Eq for Fixed

Source§

impl FromStr for Fixed

Source§

fn from_str(s: &str) -> Result<Fixed, ParseFixedError>

Parses [-+]digits[.digits], with an optional d or D suffix as in IDL literals.

Source§

type Err = ParseFixedError

The associated error which can be returned from parsing.
Source§

impl PartialEq for Fixed

Source§

fn eq(&self, other: &Fixed) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Forget for Fixed

§

impl Freeze for Fixed

§

impl Move for Fixed

§

impl RefUnwindSafe for Fixed

§

impl Send for Fixed

§

impl Sync for Fixed

§

impl Unpin for Fixed

§

impl UnsafeUnpin for Fixed

§

impl UnwindSafe for Fixed

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more