Trait JsonRef

Source
pub trait JsonRef<'a>: Copy + Debug {
    type Owned: Json<Borrowed<'a> = Self> + 'a;
    type Array: ArrayRef<'a, JsonRef = Self>;
    type Object: ObjectRef<'a, JsonRef = Self>;

Show 13 methods // Required methods fn to_owned(self) -> Self::Owned; fn null() -> Self; fn as_bool(self) -> Option<bool>; fn as_number(self) -> Option<Number>; fn as_str(self) -> Option<&'a str>; fn as_array(self) -> Option<Self::Array>; fn as_object(self) -> Option<Self::Object>; fn is_null(self) -> bool; // Provided methods fn is_bool(self) -> bool { ... } fn is_number(self) -> bool { ... } fn is_string(self) -> bool { ... } fn is_array(self) -> bool { ... } fn is_object(self) -> bool { ... }
}
Expand description

A trait for borrowed JSON values.

Required Associated Types§

Source

type Owned: Json<Borrowed<'a> = Self> + 'a

The type of owned JSON values.

Source

type Array: ArrayRef<'a, JsonRef = Self>

The type of borrowed JSON arrays.

Source

type Object: ObjectRef<'a, JsonRef = Self>

The type of borrowed JSON objects.

Required Methods§

Source

fn to_owned(self) -> Self::Owned

Creates an owned JSON value.

Source

fn null() -> Self

Returns a null value.

Source

fn as_bool(self) -> Option<bool>

If the JSON is a boolean, returns the associated bool. Returns None otherwise.

Source

fn as_number(self) -> Option<Number>

If the JSON is a number, returns the associated number. Returns None otherwise.

Source

fn as_str(self) -> Option<&'a str>

If the JSON is a string, returns the associated string. Returns None otherwise.

Source

fn as_array(self) -> Option<Self::Array>

If the JSON is an array, returns the associated array. Returns None otherwise.

Source

fn as_object(self) -> Option<Self::Object>

If the JSON is an object, returns the associated object. Returns None otherwise.

Source

fn is_null(self) -> bool

Returns true if the value is null.

Provided Methods§

Source

fn is_bool(self) -> bool

Returns true if the value is a boolean.

Source

fn is_number(self) -> bool

Returns true if the value is a number.

Source

fn is_string(self) -> bool

Returns true if the value is a string.

Source

fn is_array(self) -> bool

Returns true if the value is an array.

Source

fn is_object(self) -> bool

Returns true if the value is an object.

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<'a> JsonRef<'a> for &'a Value

Source§

type Owned = Value

Source§

type Array = &'a Vec<Value>

Source§

type Object = &'a Map<String, Value>

Source§

fn to_owned(self) -> Self::Owned

Source§

fn null() -> Self

Source§

fn is_null(self) -> bool

Source§

fn as_bool(self) -> Option<bool>

Source§

fn as_number(self) -> Option<Number>

Source§

fn as_str(self) -> Option<&'a str>

Source§

fn as_array(self) -> Option<Self::Array>

Source§

fn as_object(self) -> Option<Self::Object>

Source§

fn is_number(self) -> bool

Source§

fn is_string(self) -> bool

Source§

fn is_array(self) -> bool

Source§

fn is_object(self) -> bool

Implementors§