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>
impl<'de, T> LoadArray<'de, T>
Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn load_with<F, O>(&mut self, f: F) -> Result<Option<O>>
pub fn load_with<F, O>(&mut self, f: F) -> Result<Option<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,
impl<T> LoadArray<'_, T>where
T: Frame,
Sourcepub fn load(&mut self) -> Result<Option<T>>
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>
impl<'de, T> LoadArray<'de, T>
Sourcepub fn read(&mut self) -> Result<Option<&'de T::Target>>
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,
impl<'de, T> LoadArray<'de, Array<T>>where
T: Marker,
Sourcepub fn load_array(&mut self) -> Result<Option<LoadArray<'de, T>>>
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,
impl<'de, T> LoadArray<'de, T>where
T: Fields,
Sourcepub fn load_struct(&mut self) -> Result<Option<T::Return<'de>>>
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>
impl<'de> LoadArray<'de, Variant>
Sourcepub fn load_variant(&mut self) -> Result<Option<Variant<'de>>>
pub fn load_variant(&mut self) -> Result<Option<Variant<'de>>>
Read the next variant from the array.
Sourcepub fn skip_variant(&mut self) -> Result<Option<&'de Signature>>
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>>
impl<'de, K, V> LoadArray<'de, Dict<K, V>>
Sourcepub fn load_entry(&mut self) -> Result<Option<(K::Return<'de>, V::Return<'de>)>>
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,
impl<'de, K> LoadArray<'de, Dict<K, Variant>>where
K: Marker,
Sourcepub fn load_entry_as<T>(
&mut self,
) -> Result<Option<(K::Return<'de>, T::Return<'de>)>>where
T: Marker,
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);