Skip to main content

LoadArray

Struct LoadArray 

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

Read an array from a buffer.

See Body::load_array.

Implementations§

Source§

impl<'de, T> LoadArray<'de, T>

Source

pub fn is_empty(&self) -> bool

Test if the array has been fully consumed.

§Examples
use tokio_dbus::BodyBuf;

let mut buf = BodyBuf::new();
let mut array = buf.store_array::<u32>()?;
array.store(10u32);
array.finish();

let mut buf = buf.as_body();
let mut array = buf.load_array::<u32>()?;
assert!(!array.is_empty());
assert_eq!(array.load()?, Some(10));
assert!(array.is_empty());
Source

pub fn load_with<F, O>(&mut self, f: F) -> Result<Option<O>>
where F: FnOnce(&mut Body<'de>) -> Result<O>,

Read the next element of the array with the given closure.

This is an escape hatch for element types which the typed readers cannot describe, and hands the closure a Body positioned at the start of the next element.

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

let mut buf = BodyBuf::new();

let mut array = buf.store_array::<(u32, ty::Variant)>()?;

array
    .store_struct()
    .store(42u32)
    .store_variant(Signature::new("as")?, |w| {
        w.store_array::<ty::Str>().store("Hello");
    })
    .finish();

array.finish();

let mut buf = buf.as_body();
let mut array = buf.load_array::<(u32, ty::Variant)>()?;

let element = array.load_with(|b| {
    b.load_struct_with(|b| {
        let n = b.load::<u32>()?;
        b.skip_variant()?;
        Ok(n)
    })
})?;

assert_eq!(element, Some(42));
assert!(array.is_empty());
Source§

impl<T> LoadArray<'_, T>
where T: Frame,

Source

pub fn load(&mut self) -> Result<Option<T>>

Load the next value from the array.

See Body::load_array.

Source§

impl<'de, T> LoadArray<'de, T>
where T: Unsized, T::Target: Read,

Source

pub fn read(&mut self) -> Result<Option<&'de T::Target>>

Read the next value from the array.

See Body::load_array.

Source§

impl<'de, T> LoadArray<'de, Array<T>>
where T: Marker,

Source

pub fn load_array(&mut self) -> Result<Option<LoadArray<'de, T>>>

Read an array from within the array.

See Body::load_struct.

Source§

impl<'de, T> LoadArray<'de, T>
where T: Fields,

Source

pub fn load_struct(&mut self) -> Result<Option<T::Return<'de>>>

Read a struct from within the array.

See Body::load_struct.

Source§

impl<'de> LoadArray<'de, Variant>

Source

pub fn load_variant(&mut self) -> Result<Option<Variant<'de>>>

Read the next variant from the array.

See StoreArray::store_variant.

Source

pub fn skip_variant(&mut self) -> Result<Option<&'de Signature>>

Skip over the next variant in the array, returning the signature of the value it contained.

See Body::skip_variant.

Source§

impl<'de, K, V> LoadArray<'de, Dict<K, V>>
where K: Marker, V: Marker,

Source

pub fn load_entry(&mut self) -> Result<Option<(K::Return<'de>, V::Return<'de>)>>

Read a dict entry from within the array.

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

let mut buf = BodyBuf::new();

let mut dict = buf.store_array::<ty::Dict<ty::Str, u32>>()?;
dict.store_entry().store("a").store(1u32).finish();
dict.store_entry().store("b").store(2u32).finish();
dict.finish();

assert_eq!(buf.signature(), "a{su}");

let mut buf = buf.as_body();
let mut dict = buf.load_array::<ty::Dict<ty::Str, u32>>()?;

assert_eq!(dict.load_entry()?, Some(("a", 1)));
assert_eq!(dict.load_entry()?, Some(("b", 2)));
assert_eq!(dict.load_entry()?, None);
Source§

impl<'de, K> LoadArray<'de, Dict<K, Variant>>
where K: Marker,

Source

pub fn load_entry_as<T>( &mut self, ) -> Result<Option<(K::Return<'de>, T::Return<'de>)>>
where T: Marker,

Read a dict entry whose value is a variant expected to contain a value of type T.

This is needed for dictionaries like the ones returned by org.freedesktop.DBus.Properties.GetAll, where the value of an entry is a container which load_entry() cannot represent.

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

let mut buf = BodyBuf::new();

let mut dict = buf.store_array::<ty::Dict<ty::Str, ty::Variant>>()?;

dict.store_entry()
    .store("IconThemePath")
    .store_variant(Signature::new("as")?, |w| {
        let mut array = w.store_array::<ty::Str>();
        array.store("/usr/share/icons");
    })
    .finish();

dict.finish();

let mut buf = buf.as_body();
let mut dict = buf.load_array::<ty::Dict<ty::Str, ty::Variant>>()?;

let Some((key, mut value)) = dict.load_entry_as::<ty::Array<ty::Str>>()? else {
    panic!("Missing entry");
};

assert_eq!(key, "IconThemePath");
assert_eq!(value.read()?, Some("/usr/share/icons"));
assert_eq!(value.read()?, None);

Auto Trait Implementations§

§

impl<'de, T> Freeze for LoadArray<'de, T>

§

impl<'de, T> RefUnwindSafe for LoadArray<'de, T>
where T: RefUnwindSafe,

§

impl<'de, T> Send for LoadArray<'de, T>
where T: Send,

§

impl<'de, T> Sync for LoadArray<'de, T>
where T: Sync,

§

impl<'de, T> Unpin for LoadArray<'de, T>
where T: Unpin,

§

impl<'de, T> UnsafeUnpin for LoadArray<'de, T>

§

impl<'de, T> UnwindSafe for LoadArray<'de, T>
where T: UnwindSafe,

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.