Struct justjson::JsonNumber

source ·
pub struct JsonNumber<'a> { /* private fields */ }
Expand description

A JSON-encoded number.

Implementations§

source§

impl<'a> JsonNumber<'a>

source

pub fn from_json(json: &'a str) -> Result<Self, Error>

Parses json, expecting a single number value.

Errors

Returns ErrorKind::ExpectedString if a non-string value is encountered.

source

pub fn source(&self) -> &str

Returns the JSON-encoded representation of this number.

source

pub fn as_f32(&self) -> Option<f32>

Parses the contained value as an f32, if possible.

The JSON parser only validates that the number takes a correct form. If a number cannot be parsed by the underlying routine due to having too many digits, it this function can return None.

source

pub fn as_f64(&self) -> Option<f64>

Parses the contained value as an f64, if possible.

The JSON parser only validates that the number takes a correct form. If a number cannot be parsed by the underlying routine due to having too many digits, it this function can return None.

source

pub fn parse<T: FromStr>(&self) -> Result<T, T::Err>

Parses the contained value.

source§

impl JsonNumber<'_>

source

pub fn as_u8(&self) -> Option<u8>

Parses the contained value as an u8 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_u16(&self) -> Option<u16>

Parses the contained value as an u16 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_u32(&self) -> Option<u32>

Parses the contained value as an u32 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_u64(&self) -> Option<u64>

Parses the contained value as an u64 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_u128(&self) -> Option<u128>

Parses the contained value as an u128 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_usize(&self) -> Option<usize>

Parses the contained value as an usize if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_i8(&self) -> Option<i8>

Parses the contained value as an i8 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_i16(&self) -> Option<i16>

Parses the contained value as an i16 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_i32(&self) -> Option<i32>

Parses the contained value as an i32 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

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

Parses the contained value as an i64 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_i128(&self) -> Option<i128>

Parses the contained value as an i128 if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

source§

impl JsonNumber<'_>

source

pub fn as_isize(&self) -> Option<isize>

Parses the contained value as an isize if possible.

If the source number is a floating point number or has a negative sign, this will always return None.

Trait Implementations§

source§

impl<'a> Clone for JsonNumber<'a>

source§

fn clone(&self) -> JsonNumber<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for JsonNumber<'a>

source§

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

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

impl<'a> PartialEq for JsonNumber<'a>

source§

fn eq(&self, other: &JsonNumber<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for JsonNumber<'a>

source§

impl<'a> StructuralEq for JsonNumber<'a>

source§

impl<'a> StructuralPartialEq for JsonNumber<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for JsonNumber<'a>

§

impl<'a> Send for JsonNumber<'a>

§

impl<'a> Sync for JsonNumber<'a>

§

impl<'a> Unpin for JsonNumber<'a>

§

impl<'a> UnwindSafe for JsonNumber<'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> 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,

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.