Skip to main content

JsonNumber

Trait JsonNumber 

Source
pub trait JsonNumber {
    // Required methods
    fn as_u64(&self) -> Option<u64>;
    fn as_i64(&self) -> Option<i64>;
    fn as_f64(&self) -> Option<f64>;
    fn as_str(&self) -> Cow<'_, str>;
    fn to_number(&self) -> Cow<'_, Number>;

    // Provided method
    fn is_integer(&self) -> bool { ... }
}
Expand description

A JSON number, readable without constructing a ::serde_json::Number.

Required Methods§

Source

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

Source

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

Source

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

Source

fn as_str(&self) -> Cow<'_, str>

Decimal digits; the only form that holds values outside the primitives.

Source

fn to_number(&self) -> Cow<'_, Number>

For cold paths: error construction and annotations.

Provided Methods§

Source

fn is_integer(&self) -> bool

type: integer checks call this per number: override it where the default’s JsonNumber::to_number round-trip is not free (e.g. decimal representations).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl JsonNumber for &Number

Source§

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

Source§

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

Source§

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

Source§

fn as_str(&self) -> Cow<'_, str>

Source§

fn to_number(&self) -> Cow<'_, Number>

Source§

impl JsonNumber for Number

Source§

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

Source§

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

Source§

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

Source§

fn as_str(&self) -> Cow<'_, str>

Source§

fn to_number(&self) -> Cow<'_, Number>

Implementors§