[−][src]Struct zvariant::DictEntry
A dictionary entry as a key-value pair.
This is not very useful on its own but since D-Bus defines it as its own type, a hashmap in D-Bus is encoded as an array of dictionary entries and GVariant even allows this to be used outside of an array, we provide this data type.
The key must be a basic data type.
Example:
use zvariant::{Decode, DictEntry}; use zvariant::{Encode, EncodingFormat, Structure}; let entry = DictEntry::new( // String key "hello", // Structure value Structure::new() .add_field(u8::max_value()) .add_field(u32::max_value()), ); assert!(entry.signature() == "{s(yu)}"); let format = EncodingFormat::default(); let encoding = entry.encode(format); assert!(encoding.len() == 24); let entry = DictEntry::decode(encoding, entry.signature(), format).unwrap(); assert!(entry.key::<String>().unwrap() == "hello"); let structure = entry.value::<Structure>().unwrap(); let fields = structure.fields(); assert!(u8::is(&fields[0])); assert!(*u8::from_variant(&fields[0]).unwrap() == u8::max_value()); assert!(u32::is(&fields[1])); assert!(*u32::from_variant(&fields[1]).unwrap() == u32::max_value());
Methods
impl DictEntry
[src]
pub fn new<K, V>(key: K, value: V) -> Self where
K: Encode + Basic,
V: Encode,
[src]
K: Encode + Basic,
V: Encode,
Create a new DictEntry
pub fn key<K>(&self) -> Result<&K, VariantError> where
K: Decode + Basic,
[src]
K: Decode + Basic,
Get a reference to the key.
pub fn value<V>(&self) -> Result<&V, VariantError> where
V: Decode,
[src]
V: Decode,
Get a reference to the value.
pub fn take<K, V>(self) -> Result<(K, V), VariantError> where
K: Decode + Basic,
V: Decode,
[src]
K: Decode + Basic,
V: Decode,
Take the key and value, consuming self
.
Trait Implementations
impl Clone for DictEntry
[src]
impl Debug for DictEntry
[src]
impl Decode for DictEntry
[src]
fn slice_data(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
fn decode(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<Self, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<Self, VariantError>
fn ensure_correct_signature(
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
[src]
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
fn slice_signature(
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
[src]
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
fn take_from_variant(variant: Variant) -> Result<Self, VariantError>
[src]
fn from_variant(variant: &Variant) -> Result<&Self, VariantError>
[src]
fn slice_for_decoding(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
impl Encode for DictEntry
[src]
const SIGNATURE_CHAR: char
[src]
const SIGNATURE_STR: &'static str
[src]
const ALIGNMENT: usize
[src]
fn encode_into(&self, bytes: &mut Vec<u8>, format: EncodingFormat)
[src]
fn signature(&self) -> Signature
[src]
fn to_variant(self) -> Variant
[src]
fn is(variant: &Variant) -> bool
[src]
fn encode(&self, format: EncodingFormat) -> Vec<u8>
[src]
fn add_padding(bytes: &mut Vec<u8>, format: EncodingFormat)
[src]
fn padding(n_bytes_before: usize, _format: EncodingFormat) -> usize
[src]
Auto Trait Implementations
impl RefUnwindSafe for DictEntry
impl Send for DictEntry
impl Sync for DictEntry
impl Unpin for DictEntry
impl UnwindSafe for DictEntry
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,