Skip to main content

Number

Struct Number 

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

An exact decimal and, once a numeric handler resolved it, its resolved options and its display form. Opaque: the digit backend is internal (owner decision 1).

Implementations§

Source§

impl Number

Source

pub fn parse(number_literal: &str) -> Option<Number>

A number-literal; None if s is not one (or is past the implementation limits: 40 significant digits, exponent ±9999).

Source

pub fn from_i64(n: i64) -> Number

n.

Source

pub fn from_f64(x: f64, host: &dyn Host) -> Option<Number>

The finite x (the shortest decimal that round-trips it, through the host); None for NaN and infinities.

Source

pub fn is_negative(&self) -> bool

Whether the value is negative (-0 included).

Source

pub fn is_integer(&self) -> bool

Whether the value is an integer.

Source

pub fn to_i64(&self) -> Option<i64>

The value as an i64, when it is an integer below 10^18 in magnitude.

Source

pub fn write_plain(&self, out: &mut dyn Sink)

Writes the exact value in plain neutral digits: -1234.5, 0.001, -0 — no exponent, no rounding.

Source

pub fn resolve( spec: NumberSpec, cx: &FnContext<'_>, operand: Option<&Value<'_>>, options: &Options<'_, '_>, errs: &mut dyn ErrorSink, ) -> Option<Number>

Resolves an expression under spec, as :number does (number.md): the operand rules, the options of spec’s function (any other option is ignored), inheritance from a number or measure operand, the digit plan and rounding. None: a fallback value, the reason reported through errs.

Source

pub fn digits(&self) -> Option<Digits<'_>>

The rounded digits to display; None for a number no handler resolved — and, with feature intl on wasm32-unknown-unknown ([crate::INTL_NUMBERS]), always: the host rounds and formats (Number::format_by_host).

Source

pub fn exact_digits(&self) -> Digits<'_>

The exact value’s digits, unrounded — how an unannotated number formats (plans/03-runtime.md §2.6): -1234.5, 0.001, -0.

Source

pub fn grouping(&self) -> Option<Grouping>

The resolved useGrouping; None when it is not set (or the number is bare).

Source

pub fn is_selectable(&self) -> bool

Whether a numeric handler resolved this number and it may select (formatting.md, “Resolve Selectors”).

Source

pub fn matches( &self, cx: &FnContext<'_>, key: &str, errs: &mut dyn ErrorSink, ) -> bool

Match(self, key) for numeric selectors (number.md, “Number Selection”): exact numeric keys, then the plural or ordinal category of the formatted digits; Bad Variant Key for any other key.

Source

pub fn better_than(key1: &str, key2: &str) -> bool

BetterThan(key1, key2) for two matching keys: an exact (numeric) key beats a keyword.

Trait Implementations§

Source§

impl Clone for Number

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 Number

The sign, whether the value is an integer, and whether a numeric handler resolved it; not the digits, whose writer a client’s formatting calls, so that a client’s build compiles that as before.

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Number

§

impl !RefUnwindSafe for Number

§

impl !Sync for Number

§

impl Send for Number

§

impl Unpin for Number

§

impl UnsafeUnpin for Number

§

impl UnwindSafe for Number

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, 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, 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.