Struct zvariant::Dict

source ·
pub struct Dict<'k, 'v> { /* private fields */ }
Expand description

A helper type to wrap dictionaries in a Value.

API is provided to convert from, and to a HashMap.

Implementations§

source§

impl<'k, 'v> Dict<'k, 'v>

source

pub fn new(key_signature: Signature<'k>, value_signature: Signature<'v>) -> Self

Create a new empty Dict, given the signature of the keys and values.

source

pub fn append<'kv: 'k, 'vv: 'v>( &mut self, key: Value<'kv>, value: Value<'vv> ) -> Result<(), Error>

Append key and value as a new entry.

§Errors
source

pub fn add<K, V>(&mut self, key: K, value: V) -> Result<(), Error>
where K: Basic + Into<Value<'k>> + Ord, V: Into<Value<'v>> + DynamicType,

Add a new entry.

source

pub fn get<'d, K, V>(&'d self, key: &'k K) -> Result<Option<V>, Error>
where &'k K: TryInto<Value<'k>>, <&'k K as TryInto<Value<'k>>>::Error: Into<Error>, V: TryFrom<&'v Value<'v>>, <V as TryFrom<&'v Value<'v>>>::Error: Into<Error>, 'd: 'k + 'v,

Get the value for the given key.

source

pub fn signature(&self) -> Signature<'static>

Get the signature of this Dict.

NB: This method potentially allocates and copies. Use full_signature if you’d like to avoid that.

source

pub fn full_signature(&self) -> &Signature<'_>

Get the signature of this Dict.

source

pub fn try_clone(&self) -> Result<Self, Error>

Try to clone the Dict.

Trait Implementations§

source§

impl<'k, 'v> Debug for Dict<'k, 'v>

source§

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

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

impl Display for Dict<'_, '_>

source§

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

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

impl<'k, 'v, K, V> From<BTreeMap<K, V>> for Dict<'k, 'v>
where K: Type + Into<Value<'k>>, V: Type + Into<Value<'v>>,

source§

fn from(value: BTreeMap<K, V>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Dict<'a, 'a>> for Value<'a>

source§

fn from(v: Dict<'a, 'a>) -> Self

Converts to this type from the input type.
source§

impl<'k, 'v, K, V, H> From<HashMap<K, V, H>> for Dict<'k, 'v>
where K: Type + Into<Value<'k>>, V: Type + Into<Value<'v>>, H: BuildHasher,

source§

fn from(value: HashMap<K, V, H>) -> Self

Converts to this type from the input type.
source§

impl<'k, 'v> Hash for Dict<'k, 'v>

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<'k, 'v> Ord for Dict<'k, 'v>

source§

fn cmp(&self, other: &Dict<'k, 'v>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'k, 'v> PartialEq for Dict<'k, 'v>

source§

fn eq(&self, other: &Dict<'k, 'v>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'k, 'v> PartialOrd for Dict<'k, 'v>

source§

fn partial_cmp(&self, other: &Dict<'k, 'v>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'k, 'v> Serialize for Dict<'k, 'v>

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<'a> TryFrom<&'a Dict<'a, 'a>> for Value<'a>

§

type Error = Error

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

fn try_from(v: &'a Dict<'a, 'a>) -> Result<Self>

Performs the conversion.
source§

impl<'a> TryFrom<&'a OwnedValue> for &'a Dict<'a, 'a>

§

type Error = Error

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

fn try_from(v: &'a OwnedValue) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Value<'_>> for &'a Dict<'a, 'a>

§

type Error = Error

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

fn try_from(value: &'a Value<'_>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&Value<'a>> for Dict<'a, 'a>

§

type Error = Error

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

fn try_from(value: &Value<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<Dict<'a, 'a>> for OwnedValue

§

type Error = Error

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

fn try_from(v: Dict<'a, 'a>) -> Result<Self>

Performs the conversion.
source§

impl<'k, 'v, K, V> TryFrom<Dict<'k, 'v>> for BTreeMap<K, V>
where K: Basic + TryFrom<Value<'k>> + Ord, V: TryFrom<Value<'v>>, K::Error: Into<Error>, V::Error: Into<Error>,

§

type Error = Error

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

fn try_from(v: Dict<'k, 'v>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'k, 'v, K, V, H> TryFrom<Dict<'k, 'v>> for HashMap<K, V, H>
where K: Basic + TryFrom<Value<'k>> + Eq + Hash, V: TryFrom<Value<'v>>, K::Error: Into<Error>, V::Error: Into<Error>, H: BuildHasher + Default,

§

type Error = Error

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

fn try_from(v: Dict<'k, 'v>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<OwnedValue> for Dict<'static, 'static>

§

type Error = Error

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

fn try_from(v: OwnedValue) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<Value<'a>> for Dict<'a, 'a>

§

type Error = Error

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

fn try_from(value: Value<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'k, 'v> Eq for Dict<'k, 'v>

source§

impl<'k, 'v> StructuralPartialEq for Dict<'k, 'v>

Auto Trait Implementations§

§

impl<'k, 'v> RefUnwindSafe for Dict<'k, 'v>

§

impl<'k, 'v> Send for Dict<'k, 'v>

§

impl<'k, 'v> Sync for Dict<'k, 'v>

§

impl<'k, 'v> Unpin for Dict<'k, 'v>

§

impl<'k, 'v> UnwindSafe for Dict<'k, 'v>

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> 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> ToString for T
where T: Display + ?Sized,

source§

default 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>,

§

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>,

§

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.