zvariant

Struct 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>> + Hash + Eq, V: Into<Value<'v>> + DynamicType,

Add a new entry.

source

pub fn get<'d, K, V>(&'d self, key: &K) -> Result<Option<&'v V>, Error>
where K: ?Sized + Eq + 'k, V: ?Sized, &'k K: TryFrom<&'k Value<'k>>, &'v V: TryFrom<&'v Value<'v>>, '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.

Trait Implementations§

source§

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

source§

fn clone(&self) -> Dict<'k, 'v>

Returns a copy 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<'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<'a> From<&'a Dict<'a, 'a>> for Value<'a>

source§

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

Converts to this type from the input type.
source§

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

source§

fn from(v: Dict<'a, 'a>) -> 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>> + Hash + Eq, V: Type + Into<Value<'v>>, H: BuildHasher + Default,

source§

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

Converts to this type from the input type.
source§

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

source§

fn eq(&self, other: &Dict<'k, 'v>) -> 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<'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 OwnedValue> for &'a Dict<'a, 'a>

source§

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

source§

type Error = Error

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

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

Performs the conversion.
source§

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

source§

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<'k, 'v, K, V, H> TryFrom<Dict<'k, 'v>> for HashMap<K, V, H>
where K: Basic + TryFrom<Value<'k>> + Hash + Eq, V: TryFrom<Value<'v>>, H: BuildHasher + Default, K::Error: Into<Error>, V::Error: Into<Error>,

source§

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>

source§

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>

source§

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

Auto Trait Implementations§

§

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

§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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§

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

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.