Skip to main content

NumberFormat

Struct NumberFormat 

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

How a source writes an amount, read once.

Built from the authored picture and never rebuilt: every engine is handed the same facts, so two engines cannot disagree about what the design said.

Implementations§

Source§

impl NumberFormat

Source

pub fn parse(spelled: &str) -> Result<Self, NumberFormatError>

Read a picture, or say what is wrong with it.

§Errors

Nothing at all, no digit place, a thousands mark in the wrong place or with the wrong number of places after it, two decimal points, digits on both sides of the symbol, or a second picture that is not the first one in brackets.

Source

pub fn spelled(&self) -> &str

The picture as the design wrote it — what a refusal quotes back.

Source

pub fn opens_with(&self) -> &str

The symbol in front of the value, empty where there is none.

Source

pub fn closes_with(&self) -> &str

The symbol after the value, empty where there is none.

Source

pub fn grouped(&self) -> bool

Whether the source writes the thousands in groups.

Source

pub fn decimals(&self) -> usize

How many places the source writes after the decimal point.

Source

pub fn negatives(&self) -> Negatives

How the source writes a value below zero.

Source

pub fn marks(&self) -> Vec<String>

The marks that are not part of the number, in the order a reader takes them out.

The symbol that opens the value, the symbol that closes it, the thousands mark, and the brackets where the source writes a negative in them. What is left is digits, at most one decimal point and at most a leading minus.

Source

pub fn shape_pattern(&self) -> String

The shape a value has to have, as a regular expression, for an engine whose own conversion raises rather than answering nothing.

It is built from the same picture the marks come from, so the guard and the reading cannot hold two opinions about one spelling. The value is matched with its surrounding spaces already gone.

Trait Implementations§

Source§

impl Clone for NumberFormat

Source§

fn clone(&self) -> NumberFormat

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 NumberFormat

Source§

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

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

impl Display for NumberFormat

Source§

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

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

impl Eq for NumberFormat

Source§

impl PartialEq for NumberFormat

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NumberFormat

Auto Trait Implementations§

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