[go: up one dir, main page]

Trait sonic_rs::JsonValue

source ·
pub trait JsonValue: Sized {
    type ValueType<'dom>
       where Self: 'dom;

Show 20 methods // Required methods fn get_type(&self) -> JsonType; fn as_number(&self) -> Option<Number>; fn as_str(&self) -> Option<&str>; fn as_bool(&self) -> Option<bool>; fn get<I: Index>(&self, index: I) -> Option<Self::ValueType<'_>>; fn pointer(&self, path: &JsonPointer<'_>) -> Option<Self::ValueType<'_>>; // Provided methods fn is_boolean(&self) -> bool { ... } fn is_true(&self) -> bool { ... } fn is_false(&self) -> bool { ... } fn is_null(&self) -> bool { ... } fn is_number(&self) -> bool { ... } fn is_str(&self) -> bool { ... } fn is_array(&self) -> bool { ... } fn is_object(&self) -> bool { ... } fn is_f64(&self) -> bool { ... } fn is_i64(&self) -> bool { ... } fn is_u64(&self) -> bool { ... } fn as_i64(&self) -> Option<i64> { ... } fn as_u64(&self) -> Option<u64> { ... } fn as_f64(&self) -> Option<f64> { ... }
}
Expand description

A trait for all JSON values. Used by Value and LazyValue.

Required Associated Types§

source

type ValueType<'dom> where Self: 'dom

Required Methods§

source

fn get_type(&self) -> JsonType

get the type of the JsonValue.

source

fn as_number(&self) -> Option<Number>

Returns the Number value of the JsonValue if it is a Number.

source

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

Returns the str if the JsonValue is a string.

source

fn as_bool(&self) -> Option<bool>

Returns the bool if the JsonValue is a boolean.

source

fn get<I: Index>(&self, index: I) -> Option<Self::ValueType<'_>>

Returns the value from index if the JsonValue is an array or object The index may be usize or &str. The usize is for array, the &str is for object.

source

fn pointer(&self, path: &JsonPointer<'_>) -> Option<Self::ValueType<'_>>

Returns the value from pointer path if the JsonValue is an array or object

Provided Methods§

source

fn is_boolean(&self) -> bool

Returns true if the JsonValue is a bool.

source

fn is_true(&self) -> bool

Returns true if the JsonValue is true.

source

fn is_false(&self) -> bool

Returns true if the JsonValue is false.

source

fn is_null(&self) -> bool

Returns true if the JsonValue is null.

source

fn is_number(&self) -> bool

Returns true if the JsonValue is a number.

source

fn is_str(&self) -> bool

Returns true if the JsonValue is a string.

source

fn is_array(&self) -> bool

Returns true if the JsonValue is an array.

source

fn is_object(&self) -> bool

Returns true if the JsonValue is an object.

source

fn is_f64(&self) -> bool

Returns true if the JsonValue is a f64.

source

fn is_i64(&self) -> bool

Returns true if the JsonValue is an i64.

source

fn is_u64(&self) -> bool

Returns true if the JsonValue is a u64.

source

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

Returns the i64 value of the JsonValue if it is a i64.

source

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

Returns the u64 value of the JsonValue if it is a u64.

source

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

Returns the f64 value of the JsonValue if it is a f64.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<V: JsonValue> JsonValue for Option<V>

§

type ValueType<'dom> = <V as JsonValue>::ValueType<'dom> where V: 'dom, Self: 'dom

source§

fn as_bool(&self) -> Option<bool>

source§

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

source§

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

source§

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

source§

fn as_number(&self) -> Option<Number>

source§

fn get_type(&self) -> JsonType

source§

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

source§

fn get<I: Index>(&self, index: I) -> Option<Self::ValueType<'_>>

source§

fn pointer(&self, path: &JsonPointer<'_>) -> Option<Self::ValueType<'_>>

source§

impl<V: JsonValue> JsonValue for &V

§

type ValueType<'dom> = <V as JsonValue>::ValueType<'dom> where V: 'dom, Self: 'dom

source§

fn as_bool(&self) -> Option<bool>

source§

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

source§

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

source§

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

source§

fn as_number(&self) -> Option<Number>

source§

fn get_type(&self) -> JsonType

source§

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

source§

fn get<I: Index>(&self, index: I) -> Option<Self::ValueType<'_>>

source§

fn pointer(&self, path: &JsonPointer<'_>) -> Option<Self::ValueType<'_>>

source§

impl<V: JsonValue> JsonValue for &mut V

§

type ValueType<'dom> = <V as JsonValue>::ValueType<'dom> where V: 'dom, Self: 'dom

source§

fn as_bool(&self) -> Option<bool>

source§

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

source§

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

source§

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

source§

fn as_number(&self) -> Option<Number>

source§

fn get_type(&self) -> JsonType

source§

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

source§

fn get<I: Index>(&self, index: I) -> Option<Self::ValueType<'_>>

source§

fn pointer(&self, path: &JsonPointer<'_>) -> Option<Self::ValueType<'_>>

source§

impl<V: JsonValue, E> JsonValue for Result<V, E>

§

type ValueType<'dom> = <V as JsonValue>::ValueType<'dom> where V: 'dom, Self: 'dom

source§

fn as_bool(&self) -> Option<bool>

source§

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

source§

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

source§

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

source§

fn as_number(&self) -> Option<Number>

source§

fn get_type(&self) -> JsonType

source§

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

source§

fn get<I: Index>(&self, index: I) -> Option<Self::ValueType<'_>>

source§

fn pointer(&self, path: &JsonPointer<'_>) -> Option<Self::ValueType<'_>>

Implementors§

source§

impl JsonValue for Document

§

type ValueType<'dom> = &'dom Value<'dom> where Self: 'dom

source§

impl<'a> JsonValue for Value<'a>

§

type ValueType<'dom> = &'dom Value<'dom> where Self: 'dom

source§

impl<'d> JsonValue for ValueMut<'d>

§

type ValueType<'dom> = &'dom Value<'dom> where Self: 'dom

source§

impl<'de> JsonValue for LazyValue<'de>

§

type ValueType<'dom> = LazyValue<'dom> where Self: 'dom