Value

Enum Value 

Source
pub enum Value<'ctx, P: Property, E: Element> {
    Null,
    Bool(bool),
    Number(Number),
    Element(E),
    Str(Cow<'ctx, str>),
    Array(Vec<Value<'ctx, P, E>>),
    Object(ObjectAsVec<'ctx, P, E>),
}
Expand description

Represents any valid JMAP value.

Variants§

§

Null

§

Bool(bool)

§

Number(Number)

§

Element(E)

§

Str(Cow<'ctx, str>)

§

Array(Vec<Value<'ctx, P, E>>)

§

Object(ObjectAsVec<'ctx, P, E>)

Implementations§

Source§

impl<'ctx, P: Property, E: Element<Property = P>> Value<'ctx, P, E>

Source

pub fn new_object() -> Self

Source

pub fn new_boolean_set( set: impl IntoIterator<Item = (Key<'ctx, P>, bool)>, ) -> Self

Source

pub fn parse_json(json: &'ctx str) -> Result<Self, String>

Source

pub fn get<I: Index<'ctx, P, E>>( &'ctx self, index: I, ) -> &'ctx Value<'ctx, P, E>

Returns a reference to the value corresponding to the key.

Source

pub fn is_object_and_contains_key(&self, key: &Key<'_, P>) -> bool

Source

pub fn is_object_and_contains_any_key(&self, keys: &[Key<'_, P>]) -> bool

Source

pub fn as_object_and_get(&self, key: &Key<'_, P>) -> Option<&Value<'ctx, P, E>>

Source

pub fn is_null(&self) -> bool

Returns true if Value is Value::Null.

Source

pub fn is_array(&self) -> bool

Returns true if Value is Value::Array.

Source

pub fn is_object(&self) -> bool

Returns true if Value is Value::Object.

Source

pub fn is_bool(&self) -> bool

Returns true if Value is Value::Bool.

Source

pub fn is_number(&self) -> bool

Returns true if Value is Value::Number.

Source

pub fn is_string(&self) -> bool

Returns true if Value is Value::Str.

Source

pub fn is_i64(&self) -> bool

Returns true if the Value is an integer between i64::MIN and i64::MAX. For any Value on which is_i64 returns true, as_i64 is guaranteed to return the integer value.

Source

pub fn is_u64(&self) -> bool

Returns true if the Value is an integer between zero and u64::MAX. For any Value on which is_u64 returns true, as_u64 is guaranteed to return the integer value.

Source

pub fn is_f64(&self) -> bool

Returns true if the Value is a f64 number.

Source

pub fn iter_array(&self) -> Option<impl Iterator<Item = &Value<'_, P, E>>>

If the Value is an Array, returns an iterator over the elements in the array.

Source

pub fn iter_object( &self, ) -> Option<impl Iterator<Item = (&Key<'_, P>, &Value<'_, P, E>)>>

If the Value is an Object, returns an iterator over the elements in the object.

Source

pub fn as_array(&self) -> Option<&[Value<'ctx, P, E>]>

If the Value is an Array, returns the associated Array. Returns None otherwise.

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value<'ctx, P, E>>>

Source

pub fn into_array(self) -> Option<Vec<Value<'ctx, P, E>>>

Source

pub fn as_object(&self) -> Option<&ObjectAsVec<'ctx, P, E>>

If the Value is an Object, returns the associated Object. Returns None otherwise.

Source

pub fn as_element(&self) -> Option<&E>

Source

pub fn as_object_mut(&mut self) -> Option<&mut ObjectAsVec<'ctx, P, E>>

Source

pub fn into_object(self) -> Option<ObjectAsVec<'ctx, P, E>>

Source

pub fn into_owned(self) -> Value<'static, P, E>

Source

pub fn into_expanded_object( self, ) -> impl Iterator<Item = (Key<'ctx, P>, Value<'ctx, P, E>)>

Source

pub fn into_expanded_boolean_set(self) -> impl Iterator<Item = Key<'ctx, P>>

Source

pub fn into_element(self) -> Option<E>

Source

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

If the Value is a Boolean, returns the associated bool. Returns None otherwise.

Source

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

If the Value is a String, returns the associated str. Returns None otherwise.

Source

pub fn into_string(self) -> Option<Cow<'ctx, str>>

Source

pub fn into_owned_string(self) -> Option<String>

Source

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

If the Value is an integer, represent it as i64 if possible. Returns None otherwise.

Source

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

If the Value is an integer, represent it as u64 if possible. Returns None otherwise.

Source

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

If the Value is a number, represent it as f64 if possible. Returns None otherwise.

Trait Implementations§

Source§

impl<'ctx, P: Clone + Property, E: Clone + Element> Clone for Value<'ctx, P, E>

Source§

fn clone(&self) -> Value<'ctx, P, E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Property, E: Element> Debug for Value<'_, P, E>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'ctx, P: Property, E: Element> Default for Value<'ctx, P, E>

Source§

fn default() -> Value<'ctx, P, E>

Returns the “default value” for a type. Read more
Source§

impl<'de, P: Property, E: Element<Property = P>> Deserialize<'de> for Value<'de, P, E>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de, P: Property, E: Element> Deserializer<'de> for &'de Value<'_, P, E>

Source§

type Error = Error

The error type that can be returned if some error occurs during deserialization.
Source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more
Source§

fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_newtype_struct<V>( self, _name: &'static str, visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a particular name.
Source§

fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_tuple<V>( self, _len: usize, visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and knows how many values there are without looking at the serialized data.
Source§

fn deserialize_tuple_struct<V>( self, _name: &'static str, _len: usize, visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a particular name and number of fields.
Source§

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_enum<V>( self, _name: &'static str, _variants: &'static [&'static str], _visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a particular name and possible variants.
Source§

fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct field or the discriminant of an enum variant.
Source§

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more
Source§

fn deserialize_unit_struct<V>( self, _name: &'static str, visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a particular name.
Source§

fn deserialize_struct<V>( self, _name: &'static str, _fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular name and fields.
Source§

fn deserialize_i128<V>( self, visitor: V, ) -> Result<<V as Visitor<'de>>::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u128<V>( self, visitor: V, ) -> Result<<V as Visitor<'de>>::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more
Source§

impl<P: Property, E: Element> Display for Value<'_, P, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, P: Property, E: Element, T: Clone + Into<Value<'a, P, E>>> From<&[T]> for Value<'a, P, E>

Source§

fn from(val: &[T]) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<&Value<'_, P, E>> for Value

Source§

fn from(val: &Value<'_, P, E>) -> Self

Converts to this type from the input type.
Source§

impl<'ctx, P: Property, E: Element> From<&'ctx Value> for Value<'ctx, P, E>

Source§

fn from(value: &'ctx Value) -> Self

Converts to this type from the input type.
Source§

impl<'a, P: Property, E: Element> From<&'a str> for Value<'a, P, E>

Source§

fn from(val: &'a str) -> Self

Converts to this type from the input type.
Source§

impl<'x, P: Property, E: Element> From<Cow<'x, str>> for Value<'x, P, E>

Source§

fn from(val: Cow<'x, str>) -> Self

Converts to this type from the input type.
Source§

impl<'x, P: Property, E: Element> From<E> for Value<'x, P, E>

Source§

fn from(element: E) -> Self

Converts to this type from the input type.
Source§

impl<'ctx, P: Property, E: Element> From<ObjectAsVec<'ctx, P, E>> for Value<'ctx, P, E>

Source§

fn from(val: ObjectAsVec<'ctx, P, E>) -> Self

Converts to this type from the input type.
Source§

impl<'x, P: Property, E: Element, T: Into<Value<'x, P, E>>> From<Option<T>> for Value<'x, P, E>

Source§

fn from(val: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<String> for Value<'_, P, E>

Source§

fn from(val: String) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<Value<'_, P, E>> for Value

Source§

fn from(val: Value<'_, P, E>) -> Self

Converts to this type from the input type.
Source§

impl<'a, P: Property, E: Element, T: Into<Value<'a, P, E>>> From<Vec<T>> for Value<'a, P, E>

Source§

fn from(val: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<bool> for Value<'_, P, E>

Source§

fn from(val: bool) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<f64> for Value<'_, P, E>

Source§

fn from(val: f64) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<i32> for Value<'_, P, E>

Source§

fn from(val: i32) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<i64> for Value<'_, P, E>

Source§

fn from(val: i64) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<isize> for Value<'_, P, E>

Source§

fn from(val: isize) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<u32> for Value<'_, P, E>

Source§

fn from(val: u32) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<u64> for Value<'_, P, E>

Source§

fn from(val: u64) -> Self

Converts to this type from the input type.
Source§

impl<P: Property, E: Element> From<usize> for Value<'_, P, E>

Source§

fn from(val: usize) -> Self

Converts to this type from the input type.
Source§

impl<'ctx, P: Hash + Property, E: Hash + Element> Hash for Value<'ctx, P, E>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'de, P: Property, E: Element> IntoDeserializer<'de> for &'de Value<'_, P, E>

Source§

type Deserializer = &'de Value<'_, P, E>

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl<'x, P: Property, E: Element> JsonPointerHandler<'x, P, E> for Value<'x, P, E>

Source§

fn eval_jptr<'y>( &'y self, pointer: JsonPointerIter<'_, P>, results: &mut Vec<Cow<'y, Value<'x, P, E>>>, )

Source§

fn patch_jptr<'y: 'x>( &mut self, pointer: JsonPointerIter<'_, P>, value: Value<'y, P, E>, ) -> bool

Source§

fn to_value<'y>(&'y self) -> Cow<'y, Value<'x, P, E>>

Source§

impl<'ctx, P: PartialEq + Property, E: PartialEq + Element> PartialEq for Value<'ctx, P, E>

Source§

fn eq(&self, other: &Value<'ctx, P, E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Property, E: Element> Serialize for Value<'_, P, E>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'x, P: Property, E: Element, T> TryFrom<Value<'x, P, E>> for HashMap<String, T>
where T: JsonPointerHandler<'x, P, E> + for<'y> TryFrom<Value<'y, P, E>> + 'static,

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value<'x, P, E>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'x, P: Property, E: Element, T> TryFrom<Value<'x, P, E>> for Vec<T>
where T: JsonPointerHandler<'x, P, E> + for<'y> TryFrom<Value<'y, P, E>> + 'static,

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value<'x, P, E>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'ctx, P: Eq + Property, E: Eq + Element> Eq for Value<'ctx, P, E>

Source§

impl<'ctx, P: Property, E: Element> StructuralPartialEq for Value<'ctx, P, E>

Auto Trait Implementations§

§

impl<'ctx, P, E> Freeze for Value<'ctx, P, E>
where E: Freeze,

§

impl<'ctx, P, E> RefUnwindSafe for Value<'ctx, P, E>

§

impl<'ctx, P, E> Send for Value<'ctx, P, E>
where E: Send, P: Send,

§

impl<'ctx, P, E> Sync for Value<'ctx, P, E>
where E: Sync, P: Sync,

§

impl<'ctx, P, E> Unpin for Value<'ctx, P, E>
where E: Unpin, P: Unpin,

§

impl<'ctx, P, E> UnwindSafe for Value<'ctx, P, E>
where E: UnwindSafe, P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.