[][src]Enum zvariant::Variant

pub enum Variant {
    U8(u8),
    Bool(bool),
    I16(i16),
    U16(u16),
    I32(i32),
    U32(u32),
    I64(i64),
    U64(u64),
    F64(f64),
    Str(String),
    Signature(Signature),
    ObjectPath(ObjectPath),
    Variant(Box<Variant>),
    Array(Array),
    DictEntry(DictEntry),
    Structure(Structure),
}

A generic container, in the form of an enum that holds exactly one value of any of the other types.

Note that this type is defined by the D-Bus specification and as such, its encoding is not the same as that of the enclosed value. For encoding the enclosed value, use encode_value method instead of Encode API. Similarly, from_data and from_data_slice decode the encoded value and wraps it in a Variant.

Example

use zvariant::{Decode, Encode, EncodingFormat, Variant};

// Create a Variant from an i16
let v = i16::max_value().to_variant();
assert!(*i16::from_variant(&v).unwrap() == i16::max_value());

// Encode it
let format = EncodingFormat::default();
let encoding = v.encode_value(format);
assert!(encoding.len() == 2);

// Decode it back
let v = Variant::from_data(encoding, v.value_signature(), format).unwrap();

// Check everything is as expected
assert!(v.value_signature() == "n");
assert!(v.signature() == "v");
assert!(i16::take_from_variant(v).unwrap() == i16::max_value());

Variants

U8(u8)
Bool(bool)
I16(i16)
U16(u16)
I32(i32)
U32(u32)
I64(i64)
U64(u64)
F64(f64)
Str(String)
Signature(Signature)
ObjectPath(ObjectPath)
Variant(Box<Variant>)
Array(Array)
DictEntry(DictEntry)
Structure(Structure)

Methods

impl Variant[src]

pub fn from_data(
    data: impl Into<SharedData>,
    signature: impl Into<Signature>,
    format: EncodingFormat
) -> Result<Self, VariantError>
[src]

Decode the first value in the encoded data and wrap it in a Variant.

pub fn from_data_slice(
    slice: impl Into<SharedData>,
    signature: impl Into<Signature>,
    format: EncodingFormat
) -> Result<Self, VariantError>
[src]

Decode the encoded value and wrap it in a Variant.

slice must have exactly 1 encoded value in it.

pub fn encode_value(&self, format: EncodingFormat) -> Vec<u8>[src]

Same as Encode::encode but instead of encoding itself, encodes the enclosed value.

pub fn encode_value_into(&self, bytes: &mut Vec<u8>, format: EncodingFormat)[src]

Same as Encode::encode_into but instead of encoding itself, encodes the enclosed value.

pub fn value_signature(&self) -> Signature[src]

Get the signature of the enclosed value.

Trait Implementations

impl Clone for Variant[src]

impl Debug for Variant[src]

impl Decode for Variant[src]

impl Encode for Variant[src]

impl SimpleDecode for Variant[src]

Auto Trait Implementations

impl RefUnwindSafe for Variant

impl Send for Variant

impl Sync for Variant

impl Unpin for Variant

impl UnwindSafe for Variant

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.