Skip to main content

StoreStruct

Struct StoreStruct 

Source
pub struct StoreStruct<'a, T> { /* private fields */ }
Expand description

Write a struct.

See BodyBuf::store_struct.

Implementations§

Source§

impl<'a, T> StoreStruct<'a, T>

Source

pub fn store( self, value: <T::First as Marker>::Return<'_>, ) -> StoreStruct<'a, T::Remaining>
where T: Fields, T::First: Marker, for<'b> <T::First as Marker>::Return<'b>: Storable,

Store a value and return the builder for the next value to store.

§Examples
use tokio_dbus::{BodyBuf, Endianness};
use tokio_dbus::ty;

let mut buf = BodyBuf::with_endianness(Endianness::LITTLE);

buf.store_struct::<(u16, u32)>()?
    .store(10u16)
    .store(10u32)
    .finish();

assert_eq!(buf.signature(), b"(qu)");
assert_eq!(buf.get(), &[10, 0, 0, 0, 10, 0, 0, 0]);

Examples using unsized types:

use tokio_dbus::{BodyBuf, Endianness};
use tokio_dbus::ty;

let mut buf = BodyBuf::with_endianness(Endianness::LITTLE);

buf.store_struct::<(ty::Str,)>()?
    .store("Hello World")
    .finish();

assert_eq!(buf.signature(), b"(s)");
assert_eq!(buf.get(), &[11, 0, 0, 0, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0]);
Source

pub fn fields(self, arguments: T)
where T: Arguments,

Store a value and return the builder for the next value to store.

§Examples
use tokio_dbus::{BodyBuf, Endianness};
use tokio_dbus::ty;

let mut buf = BodyBuf::with_endianness(Endianness::LITTLE);

buf.store_struct::<(u8, u32)>()?.fields((42u8, 42u32));

assert_eq!(buf.signature(), b"(yu)");
assert_eq!(buf.get(), &[42, 0, 0, 0, 42, 0, 0, 0]);
Source

pub fn store_array<W, U>(self, writer: W) -> StoreStruct<'a, T::Remaining>
where W: FnOnce(&mut StoreArray<'_, U>), T: Fields<First = Array<U>>, U: Aligned,

Store a value and return the builder for the next value to store.

§Examples
use tokio_dbus::{BodyBuf, Endianness};
use tokio_dbus::ty;

let mut buf = BodyBuf::with_endianness(Endianness::LITTLE);

buf.store_struct::<(ty::Array<u32>,)>()?
    .store_array(|w| {
        w.store(1);
        w.store(2);
        w.store(3);
        w.store(4);
    })
    .finish();

assert_eq!(buf.signature(), b"(au)");
assert_eq!(buf.get(), &[16, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
Source

pub fn store_struct<W>(self, writer: W) -> StoreStruct<'a, T::Remaining>
where W: FnOnce(StoreStruct<'_, T::First>), T: Fields, T::First: Fields,

Store a nested struct and return the builder for the next value to store.

§Examples
use tokio_dbus::{BodyBuf, Endianness};
use tokio_dbus::ty;

let mut buf = BodyBuf::with_endianness(Endianness::LITTLE);

buf.store_struct::<((u32, ty::Str), u8)>()?
    .store_struct(|w| {
        w.store(42u32).store("Hello World").finish();
    })
    .store(1u8)
    .finish();

assert_eq!(buf.signature(), b"((us)y)");

let mut buf = buf.as_body();
let ((n, string), b) = buf.load_struct::<((u32, ty::Str), u8)>()?;

assert_eq!(n, 42);
assert_eq!(string, "Hello World");
assert_eq!(b, 1);
Source

pub fn store_variant<W>( self, signature: &Signature, writer: W, ) -> StoreStruct<'a, T::Remaining>
where W: FnOnce(StoreVariant<'_>), T: Fields<First = Variant>,

Store a variant and return the builder for the next value to store.

§Examples
use tokio_dbus::{ty, BodyBuf, Signature, Variant};

let mut buf = BodyBuf::new();

buf.store_struct::<(u32, ty::Variant)>()?
    .store(42u32)
    .store_variant(Signature::STRING, |w| w.store("Hello World!"))
    .finish();

assert_eq!(buf.signature(), "(uv)");

let mut buf = buf.as_body();
let (n, value) = buf.load_struct::<(u32, ty::Variant)>()?;

assert_eq!(n, 42);
assert_eq!(value, Variant::String("Hello World!"));
Source§

impl StoreStruct<'_, ()>

Source

pub fn finish(self)

Finish writing the struct.

See BodyBuf::store_struct.

Auto Trait Implementations§

§

impl<'a, T> !UnwindSafe for StoreStruct<'a, T>

§

impl<'a, T> Freeze for StoreStruct<'a, T>

§

impl<'a, T> RefUnwindSafe for StoreStruct<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for StoreStruct<'a, T>
where T: Send,

§

impl<'a, T> Sync for StoreStruct<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for StoreStruct<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for StoreStruct<'a, T>

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.