Skip to main content

Json

Trait Json 

Source
pub trait Json: Sized + Eq {
    type MetaData: Clone + Sync + Send;
    type Number: Number;
    type String: Eq + Deref<Target = str> + for<'a> From<&'a str>;
    type Array: Get<usize, Item = Self> + Len + Iter + IntoIterator<Item = Self>;
    type Key: Key<Self::MetaData>;
    type Object: Keyed<Key = Self::Key, Item = Self> + Len + for<'a> Get<&'a str> + for<'a> GetKeyValue<&'a str> + MapIter + IntoIterator<Item = (Self::Key, Self)>;

Show 31 methods // Required methods fn as_value_ref(&self) -> ValueRef<'_, Self>; fn as_value_mut(&mut self) -> ValueMut<'_, Self>; fn into_parts(self) -> (Value<Self>, Self::MetaData); fn metadata(&self) -> &Self::MetaData; fn as_pair_mut(&mut self) -> (ValueMut<'_, Self>, &Self::MetaData); // Provided methods fn into_value(self) -> Value<Self> { ... } fn as_pair(&self) -> (ValueRef<'_, Self>, &Self::MetaData) { ... } fn is_null(&self) -> bool { ... } fn is_empty_array(&self) -> bool { ... } fn is_empty_object(&self) -> bool { ... } fn is_empty_array_or_object(&self) -> bool { ... } 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 { ... } fn as_bool(&self) -> Option<bool> { ... } fn as_number(&self) -> Option<&Self::Number> { ... } fn as_u32(&self) -> Option<u32> { ... } fn as_u64(&self) -> Option<u64> { ... } fn as_i32(&self) -> Option<i32> { ... } fn as_i64(&self) -> Option<i64> { ... } fn as_f32(&self) -> Option<f32> { ... } fn as_f32_lossy(&self) -> Option<f32> { ... } fn as_f64(&self) -> Option<f64> { ... } fn as_f64_lossy(&self) -> Option<f64> { ... } fn as_str(&self) -> Option<&str> { ... } fn as_array(&self) -> Option<&Self::Array> { ... } fn as_array_mut(&mut self) -> Option<&mut Self::Array> { ... } fn as_object(&self) -> Option<&Self::Object> { ... } fn as_object_mut(&mut self) -> Option<&mut Self::Object> { ... }
}
Expand description

JSON value attached to some metadata.

Required Associated Types§

Source

type MetaData: Clone + Sync + Send

Metadata type attached to each value.

The metadata should be ignored during comparison/ordering/hashing of JSON values.

Source

type Number: Number

Literal number type.

Source

type String: Eq + Deref<Target = str> + for<'a> From<&'a str>

String type.

Source

type Array: Get<usize, Item = Self> + Len + Iter + IntoIterator<Item = Self>

Array type.

Source

type Key: Key<Self::MetaData>

Object key type.

Source

type Object: Keyed<Key = Self::Key, Item = Self> + Len + for<'a> Get<&'a str> + for<'a> GetKeyValue<&'a str> + MapIter + IntoIterator<Item = (Self::Key, Self)>

Object type.

Required Methods§

Source

fn as_value_ref(&self) -> ValueRef<'_, Self>

Returns a reference to the actual JSON value (without the metadata).

Source

fn as_value_mut(&mut self) -> ValueMut<'_, Self>

Returns a mutable reference to the actual JSON value (without the metadata).

Source

fn into_parts(self) -> (Value<Self>, Self::MetaData)

Transforms this JSON value into a Value and MetaData.

Source

fn metadata(&self) -> &Self::MetaData

Returns a reference to the metadata associated to the JSON value.

Source

fn as_pair_mut(&mut self) -> (ValueMut<'_, Self>, &Self::MetaData)

Returns a pair containing a mutable reference to the JSON value and a reference to its metadata.

Provided Methods§

Source

fn into_value(self) -> Value<Self>

Transforms this JSON value into a Value.

Source

fn as_pair(&self) -> (ValueRef<'_, Self>, &Self::MetaData)

Returns a pair containing a reference to the JSON value and a reference to its metadata.

Source

fn is_null(&self) -> bool

Returns true if the value is a Null. Returns false otherwise.

Source

fn is_empty_array(&self) -> bool

Checks if the value is an empty array.

Source

fn is_empty_object(&self) -> bool

Checks if the value is an empty object.

Source

fn is_empty_array_or_object(&self) -> bool

Checks if the value is an empty array or empty object.

Source

fn is_bool(&self) -> bool

Returns true if the value is a boolean. Returns false otherwise.

For any value on which is_bool returns true, as_bool is guaranteed to return the boolean value.

Source

fn is_number(&self) -> bool

Returns true if the value is a number. Returns false otherwise.

For any value on which is_number returns true, as_number is guaranteed to return the number value.

Source

fn is_string(&self) -> bool

Returns true if the value is a string. Returns false otherwise.

For any value on which is_string returns true, as_str is guaranteed to return the string value.

Source

fn is_array(&self) -> bool

Returns true if the value is an array. Returns false otherwise.

For any value on which is_array returns true, as_array is guaranteed to return the array value.

Source

fn is_object(&self) -> bool

Returns true if the value is an object. Returns false otherwise.

For any value on which is_object returns true, as_object is guaranteed to return the object value.

Source

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

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

Source

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

If the value is a number, returns a reference to it. Returns None otherwise.

Source

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

Returns this number as an u32 if it can be exactly represented as such.

Source

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

Returns this number as an u64 if it can be exactly represented as such.

Source

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

Returns this number as an i32 if it can be exactly represented as such.

Source

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

Returns this number as an i64 if it can be exactly represented as such.

Source

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

Returns this number as an f32 if it can be exactly represented as such.

Source

fn as_f32_lossy(&self) -> Option<f32>

Returns this number as an f32 if it is a number, potentially losing precision in the process.

Source

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

Returns this number as an f64 if it can be exactly represented as such.

Source

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

Returns this number as an f64 if it is a number, potentially losing precision in the process.

Source

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

If the value is a string, returns its associated str. Returns None otherwise.

Source

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

If the value is an array, returns a reference to it. Returns None otherwise.

Source

fn as_array_mut(&mut self) -> Option<&mut Self::Array>

If the value is an array, returns a mutable reference to it. Returns None otherwise.

Source

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

If the value is an object, returns a reference to it. Returns None otherwise.

Source

fn as_object_mut(&mut self) -> Option<&mut Self::Object>

If the value is an object, returns a mutable reference to it. Returns None otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§