Trait Json

Source
pub trait Json: Clone + Debug {
    type Borrowed<'a>: JsonRef<'a, Owned = Self>
       where Self: 'a;

    // Required methods
    fn as_ref(&self) -> Self::Borrowed<'_>;
    fn null() -> Self;
    fn bool(b: bool) -> Self;
    fn from_u64(v: u64) -> Self;
    fn from_i64(v: i64) -> Self;
    fn from_f64(v: f64) -> Self;
    fn from_number(n: Number) -> Self;
    fn from_string(s: &str) -> Self;
    fn object<'a, I: IntoIterator<Item = (&'a str, Self)>>(i: I) -> Self;

    // Provided method
    fn borrow<'b, 'a: 'b>(p: Self::Borrowed<'a>) -> Self::Borrowed<'b> { ... }
}
Expand description

A trait for owned JSON values.

Required Associated Types§

Source

type Borrowed<'a>: JsonRef<'a, Owned = Self> where Self: 'a

The type of borrowed JSON values.

Required Methods§

Source

fn as_ref(&self) -> Self::Borrowed<'_>

Returns a reference to the JSON value.

Source

fn null() -> Self

Returns a null value.

Source

fn bool(b: bool) -> Self

Returns a boolean value.

Source

fn from_u64(v: u64) -> Self

Returns a number value from u64.

Source

fn from_i64(v: i64) -> Self

Returns a number value from i64.

Source

fn from_f64(v: f64) -> Self

Returns a number value from f64.

Source

fn from_number(n: Number) -> Self

Returns a number value.

Source

fn from_string(s: &str) -> Self

Returns a string value.

Source

fn object<'a, I: IntoIterator<Item = (&'a str, Self)>>(i: I) -> Self

Returns an object.

Provided Methods§

Source

fn borrow<'b, 'a: 'b>(p: Self::Borrowed<'a>) -> Self::Borrowed<'b>

Narrow down the lifetime of a borrowed value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Json for Value

Source§

type Borrowed<'a> = &'a Value

Source§

fn as_ref(&self) -> Self::Borrowed<'_>

Source§

fn null() -> Self

Source§

fn bool(b: bool) -> Self

Source§

fn from_u64(v: u64) -> Self

Source§

fn from_i64(v: i64) -> Self

Source§

fn from_f64(v: f64) -> Self

Source§

fn from_number(n: Number) -> Self

Source§

fn from_string(s: &str) -> Self

Source§

fn object<'a, I: IntoIterator<Item = (&'a str, Self)>>(iter: I) -> Self

Implementors§