Skip to main content

JsonNumberToken

Struct JsonNumberToken 

Source
pub struct JsonNumberToken<'call> { /* private fields */ }
Expand description

A syntactically validated number token borrowed from the input document.

The token is only valid during the synchronous validated-decoding callback that supplied it; its source spelling cannot outlive that callback. Offsets are byte offsets from the beginning of the source document. The exact safe-integer range is the closed interval [-9007199254740991, 9007199254740991]. Decimal or exponent spellings are interpreted exactly, without an intermediate floating-point conversion.

§Examples

use qubit_json::decode::{JsonDecoder, JsonNumberPolicy, JsonValidatedDecodeOptions};

let options = JsonValidatedDecodeOptions::builder().build();
let owner = JsonDecoder::unlimited().decode_unique_validated_str(
    "1.00e2", &options, |path, token| {
        assert!(path.is_empty());
        assert_eq!(token.raw(), "1.00e2");
        assert_eq!(token.offset(), 0);
        assert_eq!(token.exact_safe_integer(), Ok(100));
        Ok::<_, std::convert::Infallible>(JsonNumberPolicy::ExactSafeInteger)
    })?;
assert_eq!(owner.as_value().as_i64(), Some(100));

Implementations§

Source§

impl<'call> JsonNumberToken<'call>

Source

pub const fn raw(&self) -> &'call str

Returns the original number spelling.

§Returns

The validated source spelling, borrowed for the callback duration.

Source

pub const fn offset(&self) -> usize

Returns the zero-based byte offset of the token in its source document.

Source

pub fn exact_safe_integer(&self) -> Result<i64, JsonNumberTokenError>

Converts an exact integral token in the IEEE-754 safe-integer range without converting through floating point.

§Returns

The represented integer when its exact mathematical value is integral and lies in [-9007199254740991, 9007199254740991].

§Errors

Returns JsonNumberTokenError::Fractional when the exact value has a fractional part, and JsonNumberTokenError::OutOfSafeIntegerRange when the exact integral value lies outside the safe-integer interval.

Trait Implementations§

Source§

impl<'call> Clone for JsonNumberToken<'call>

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<'call> Copy for JsonNumberToken<'call>

Source§

impl<'call> Debug for JsonNumberToken<'call>

Source§

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

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

impl<'call> Eq for JsonNumberToken<'call>

Source§

impl<'call> PartialEq for JsonNumberToken<'call>

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
Source§

impl<'call> StructuralPartialEq for JsonNumberToken<'call>

Auto Trait Implementations§

§

impl<'call> Freeze for JsonNumberToken<'call>

§

impl<'call> RefUnwindSafe for JsonNumberToken<'call>

§

impl<'call> Send for JsonNumberToken<'call>

§

impl<'call> Sync for JsonNumberToken<'call>

§

impl<'call> Unpin for JsonNumberToken<'call>

§

impl<'call> UnsafeUnpin for JsonNumberToken<'call>

§

impl<'call> UnwindSafe for JsonNumberToken<'call>

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.