Skip to main content

Number

Struct Number 

Source
pub struct Number<'a> { /* private fields */ }
Expand description

A number as the cursor read it.

text is the number exactly as written. as_i64 and as_f64 give its value exactly, from the digits the cursor read while it checked the number’s grammar, so most numbers need no second pass over their text.

Implementations§

Source§

impl<'a> Number<'a>

Source

pub fn text(&self) -> &'a str

The number exactly as written: 12.50 stays 12.50, and a 30-digit integer keeps every digit.

Source

pub fn is_integer(&self) -> bool

Whether it is written with digits only, with no point and no exponent: 7 is, 7.0 and 7e0 are not.

Source

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

The number as an i64, exactly, when it is a whole number that fits, however it is written: 7, 7.0, 700e-2 and 1e3 all are, and -0 is 0. 1.5 and 9223372036854775808 are None. No float is used on the way: a fraction is never cut, nor a digit rounded.

Source

pub fn as_f64(&self) -> f64

The nearest f64, correctly rounded, exactly as Rust’s own parser gives it: 1e400 is infinite, and -0 is negative zero.

Most numbers take one multiplication or division, with no second pass. Digits that fit 2^53 and a power of ten up to 10^22 are both exact in a double, so one rounding gives the nearest (Clinger’s fast path). A larger power still qualifies when part of it moves into the digits and they still fit, as 123e30 is 123000000 × 10^22. The rest go through str::parse.

Trait Implementations§

Source§

impl<'a> Clone for Number<'a>

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<'a> Copy for Number<'a>

Source§

impl Debug for Number<'_>

Source§

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

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

impl Eq for Number<'_>

Source§

impl PartialEq for Number<'_>

Two numbers are equal when they are written the same.

Source§

fn eq(&self, other: &Self) -> 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<'a> Forget for Number<'a>

§

impl<'a> Freeze for Number<'a>

§

impl<'a> RefUnwindSafe for Number<'a>

§

impl<'a> Send for Number<'a>

§

impl<'a> Sync for Number<'a>

§

impl<'a> Unpin for Number<'a>

§

impl<'a> UnsafeUnpin for Number<'a>

§

impl<'a> UnwindSafe for Number<'a>

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.