Skip to main content

Variant

Enum Variant 

Source
#[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<'_>

Source

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§

Source§

impl<'de> Clone for Variant<'de>

Source§

fn clone(&self) -> Variant<'de>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'de> Copy for Variant<'de>

Source§

impl<'de> Debug for Variant<'de>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> PartialEq for Variant<'de>

Source§

fn eq(&self, other: &Variant<'de>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Storable for Variant<'_>

Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.