pub struct StoreVariant<'a> { /* private fields */ }Expand description
Write the contents of a variant.
The signature of the contained value is written when this is constructed, after which exactly one value matching that signature must be stored.
Unlike the other writers in this crate a variant is written against a
signature which is provided at runtime. This is what makes it possible to
write recursive types, such as the (ia{sv}av) layout of a
com.canonical.dbusmenu menu.
Implementations§
Source§impl<'a> StoreVariant<'a>
impl<'a> StoreVariant<'a>
Sourcepub fn store<T>(self, value: T)where
T: Storable,
pub fn store<T>(self, value: T)where
T: Storable,
Store a value inside of the variant.
Note that a Variant must not be stored this way, since it writes
its own signature and would end up writing it twice. Store it directly
instead, with BodyBuf::store or the store of the surrounding
container.
§Examples
use tokio_dbus::{BodyBuf, Signature, Variant};
let mut buf = BodyBuf::new();
buf.store_variant(Signature::STRING)?.store("Hello World!");
assert_eq!(buf.signature(), Signature::VARIANT);
let mut buf = buf.as_body();
assert_eq!(buf.read_variant()?, Variant::String("Hello World!"));Sourcepub fn store_array<E>(self) -> StoreArray<'a, E>where
E: Aligned,
pub fn store_array<E>(self) -> StoreArray<'a, E>where
E: Aligned,
Store an array inside of the variant.
§Examples
use tokio_dbus::{ty, BodyBuf, Signature};
let mut buf = BodyBuf::new();
let mut array = buf.store_variant(Signature::new("as")?)?.store_array::<ty::Str>();
array.store("Hello");
array.store("World");
array.finish();
assert_eq!(buf.signature(), Signature::VARIANT);
let mut buf = buf.as_body();
assert_eq!(buf.skip_variant()?, Signature::new("as")?);Sourcepub fn store_struct<F>(self) -> StoreStruct<'a, F>where
F: Fields,
pub fn store_struct<F>(self) -> StoreStruct<'a, F>where
F: Fields,
Store a struct inside of the variant.
§Examples
use tokio_dbus::{ty, BodyBuf, Signature};
let mut buf = BodyBuf::new();
buf.store_variant(Signature::new("(us)")?)?
.store_struct::<(u32, ty::Str)>()
.store(42u32)
.store("Hello World!")
.finish();
assert_eq!(buf.signature(), Signature::VARIANT);
let mut buf = buf.as_body();
assert_eq!(buf.skip_variant()?, Signature::new("(us)")?);Auto Trait Implementations§
impl<'a> !UnwindSafe for StoreVariant<'a>
impl<'a> Freeze for StoreVariant<'a>
impl<'a> RefUnwindSafe for StoreVariant<'a>
impl<'a> Send for StoreVariant<'a>
impl<'a> Sync for StoreVariant<'a>
impl<'a> Unpin for StoreVariant<'a>
impl<'a> UnsafeUnpin for StoreVariant<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more