Skip to main content

StoreVariant

Struct StoreVariant 

Source
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.

See BodyBuf::store_variant.

Implementations§

Source§

impl<'a> StoreVariant<'a>

Source

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!"));
Source

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")?);
Source

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