[−][src]Enum zvariant::Variant
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)
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]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<Self, VariantError>
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]
slice: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<Self, VariantError>
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]
fn slice_data(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
fn decode(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<Self, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<Self, VariantError>
fn take_from_variant(variant: Variant) -> Result<Self, VariantError>
[src]
fn from_variant(variant: &Variant) -> Result<&Self, VariantError>
[src]
fn ensure_correct_signature(
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
[src]
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
fn slice_signature(
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
[src]
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
fn slice_for_decoding(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
impl Encode for Variant
[src]
const SIGNATURE_CHAR: char
[src]
const SIGNATURE_STR: &'static str
[src]
const ALIGNMENT: usize
[src]
fn encode_into(&self, bytes: &mut Vec<u8>, format: EncodingFormat)
[src]
fn to_variant(self) -> Variant
[src]
fn is(variant: &Variant) -> bool
[src]
fn encode(&self, format: EncodingFormat) -> Vec<u8>
[src]
fn signature(&self) -> Signature
[src]
fn add_padding(bytes: &mut Vec<u8>, format: EncodingFormat)
[src]
fn padding(n_bytes_before: usize, _format: EncodingFormat) -> usize
[src]
impl SimpleDecode for Variant
[src]
fn slice_data_simple(
data: impl Into<SharedData>,
format: EncodingFormat
) -> Result<SharedData, VariantError> where
Self: Sized,
[src]
data: impl Into<SharedData>,
format: EncodingFormat
) -> Result<SharedData, VariantError> where
Self: Sized,
fn decode_simple(
data: impl Into<SharedData>,
format: EncodingFormat
) -> Result<Self, VariantError> where
Self: Sized,
[src]
data: impl Into<SharedData>,
format: EncodingFormat
) -> Result<Self, VariantError> where
Self: Sized,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,