#[non_exhaustive]pub enum Variant<'de> {
Bool(bool),
U8(u8),
I16(i16),
U16(u16),
I32(i32),
U32(u32),
I64(i64),
U64(u64),
F64(f64),
String(&'de str),
ObjectPath(&'de ObjectPath),
Signature(&'de Signature),
}Expand description
A variant holding a value of a basic D-Bus type.
A variant is a value which is prefixed by the Signature of the value it
contains, which allows a container to hold values of a type which is not
known ahead of time.
Containers inside of a variant cannot be represented by this type. To write
one use BodyBuf::store_variant, and to read one use
Body::skip_variant to skip over it.
§Examples
use tokio_dbus::{BodyBuf, Variant};
let mut body = BodyBuf::new();
body.store(Variant::String("Hello World!"))?;
body.store(Variant::Bool(true))?;
assert_eq!(body.signature(), "vv");
let mut body = body.as_body();
assert!(matches!(body.read_variant()?, Variant::String("Hello World!")));
assert!(matches!(body.read_variant()?, Variant::Bool(true)));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Bool(bool)
A boolean variant.
U8(u8)
A single byte variant.
I16(i16)
A signed 16-bit variant.
U16(u16)
An unsigned 16-bit variant.
I32(i32)
A signed 32-bit variant.
U32(u32)
An unsigned 32-bit variant.
I64(i64)
A signed 64-bit variant.
U64(u64)
An unsigned 64-bit variant.
F64(f64)
A 64-bit floating point variant.
String(&'de str)
A string variant.
ObjectPath(&'de ObjectPath)
An object path variant.
Signature(&'de Signature)
A stored signature.
Implementations§
Source§impl Variant<'_>
impl Variant<'_>
Sourcepub fn contained_signature(&self) -> &'static Signature
pub fn contained_signature(&self) -> &'static Signature
The signature of the value contained in this variant.
§Examples
use tokio_dbus::{Signature, Variant};
assert_eq!(Variant::Bool(true).contained_signature(), Signature::BOOLEAN);
assert_eq!(Variant::String("hi").contained_signature(), Signature::STRING);Trait Implementations§
impl<'de> Copy for Variant<'de>
impl Storable for Variant<'_>
impl<'de> StructuralPartialEq for Variant<'de>
Auto Trait Implementations§
impl<'de> Freeze for Variant<'de>
impl<'de> RefUnwindSafe for Variant<'de>
impl<'de> Send for Variant<'de>
impl<'de> Sync for Variant<'de>
impl<'de> Unpin for Variant<'de>
impl<'de> UnsafeUnpin for Variant<'de>
impl<'de> UnwindSafe for Variant<'de>
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