[][src]Trait zvariant::Decode

pub trait Decode: Encode + Debug {
    fn decode(
        data: impl Into<SharedData>,
        signature: impl Into<Signature>,
        format: EncodingFormat
    ) -> Result<Self, VariantError>
    where
        Self: Sized
;
fn take_from_variant(variant: Variant) -> Result<Self, VariantError>
    where
        Self: Sized
;
fn from_variant(variant: &Variant) -> Result<&Self, VariantError>; fn slice_data(
        data: impl Into<SharedData>,
        signature: impl Into<Signature>,
        format: EncodingFormat
    ) -> Result<SharedData, VariantError>
    where
        Self: Sized
, { ... }
fn ensure_correct_signature(
        signature: impl Into<Signature>
    ) -> Result<Signature, VariantError> { ... }
fn slice_signature(
        signature: impl Into<Signature>
    ) -> Result<Signature, VariantError> { ... }
fn slice_for_decoding(
        data: impl Into<SharedData>,
        signature: impl Into<Signature>,
        format: EncodingFormat
    ) -> Result<SharedData, VariantError> { ... } }

Trait for decoding of varius types from encoded form.

All data types that implement Encode also implement Decode. As decoding require allocation, one exception here is &str. It only implements Encode, while its owned sibling, String implements both traits.

Required methods

fn decode(
    data: impl Into<SharedData>,
    signature: impl Into<Signature>,
    format: EncodingFormat
) -> Result<Self, VariantError> where
    Self: Sized

Decode instance of implementing type from the data slice.

Unless data only contains one item of implementing type, you need to call slice_data to get the slice before you can call this function. For simple types, you might want to use SimpleDecode::decode_simple instead.

fn take_from_variant(variant: Variant) -> Result<Self, VariantError> where
    Self: Sized

Flatten the variant to enclosed value of the implementing type.

TryFrom<Variant> bound on Decode trait would have been better but we can't do that unfortunately since Variant implements Decode.

fn from_variant(variant: &Variant) -> Result<&Self, VariantError>

Flatten the variant reference to a reference of the enclosed value of the implementing type.

Loading content...

Provided methods

fn slice_data(
    data: impl Into<SharedData>,
    signature: impl Into<Signature>,
    format: EncodingFormat
) -> Result<SharedData, VariantError> where
    Self: Sized

Get the slice of data that belongs to implementing type.

Unless data only contains one item of implementing type, you need to call this function to get the slice before you can call decode. For simple types, you might want to use SimpleDecode::slice_data_simple instead.

The default implementation works for constant-sized types whose size is the same as their alignment

fn ensure_correct_signature(
    signature: impl Into<Signature>
) -> Result<Signature, VariantError>

Ensure given signature is correct and of the implementing type.

The default implementation works for simple types whose signature is constant.

fn slice_signature(
    signature: impl Into<Signature>
) -> Result<Signature, VariantError>

Get the slice of signature that belongs to implementing type.

This is used for getting individual signatures from container signatures. The default implementation works for simple types with single-character signatures.

Example:

use zvariant::{Decode, Encode};

let container_sig = "sux";
let str_sig = String::slice_signature(container_sig).unwrap();
assert!(str_sig == String::SIGNATURE_STR);
let mut parsed = str_sig.len();

let u32_sig = u32::slice_signature(&container_sig[parsed..]).unwrap();
assert!(u32_sig == u32::SIGNATURE_STR);
parsed += u32_sig.len();

let i64_sig = i64::slice_signature(&container_sig[parsed..]).unwrap();
assert!(i64_sig == i64::SIGNATURE_STR);

fn slice_for_decoding(
    data: impl Into<SharedData>,
    signature: impl Into<Signature>,
    format: EncodingFormat
) -> Result<SharedData, VariantError>

A helper for decode implementation. Removes any leading padding bytes.

Loading content...

Implementations on Foreign Types

impl Decode for u8[src]

impl Decode for bool[src]

impl Decode for i16[src]

impl Decode for u16[src]

impl Decode for i32[src]

impl Decode for u32[src]

impl Decode for i64[src]

impl Decode for u64[src]

impl Decode for f64[src]

impl Decode for String[src]

Loading content...

Implementors

impl Decode for Variant[src]

impl Decode for Array[src]

impl Decode for DictEntry[src]

impl Decode for ObjectPath[src]

impl Decode for Signature[src]

impl Decode for Structure[src]

Loading content...