[][src]Struct gvariant::Variant

#[repr(transparent)]pub struct Variant(_);

The GVariant Variant v type

The Variant type can contain any GVariant value.

Non-spec conformant implementation of Equality with non-normal form data

While every value has a single canoncial byte representation ("normal form") there other representations that have the same value. For example: values of type (yi) have 3B of padding between the y and the i. In normal form these bytes are 0, but they are irrelevant for the actual value. Ignoring the value of the padding bytes is correct according to the spec.

This is handled correctly when comparing the values of two (yi) instances in rust code. What isn't correct is the handling of Variant v types that contain non-normal data with respect to checking for equality. Correct checking of equality would require deserialising the data according to the typestr contained within the variant, and then doing the comparison. We don't do run-time interpretation of typestrs in this crate, prefering to do it at compile time. Instead we just compare the underlying data. This gives correct results for data in normal form, but there will be some false-negatives for non-normal form data.

Therefore Variant implements PartialEq, but not Eq because the comparison is not "reflexive".

Implementations

impl Variant[src]

pub fn get<M: Marker>(&self, m: M) -> Option<&M::Type> where
    AlignedSlice<A8>: AsAligned<<M::Type as AlignOf>::AlignOf>, 
[src]

Get the value from the variant, if it matches the type passed in.

Example:

let a = v.get(gv!("ai"));
// a now has type &[i32]

pub fn split(&self) -> (&[u8], &AlignedSlice<A8>)[src]

Destructures the variant into (typestr, data).

Note: typestr is not guaranteed to be a valid GVariant type.

Example use:

match v.split() {
    (b"(is)", _) => {
        let s = v.get(gv!("(is)"));
        // Do something with s
    }
    (ty, _) => panic!("Unexpected variant type {:?}", ty)
}

Trait Implementations

impl AlignOf for Variant[src]

type AlignOf = A8

impl AllBitPatternsValid for Variant[src]

impl Cast for Variant[src]

impl Debug for Variant[src]

impl PartialEq<Variant> for Variant[src]

fn eq(&self, other: &Self) -> bool[src]

Caveat: The current implementation has false negatives for data not in "normal form". This may change in the future.

impl RefCast for Variant[src]

type From = AlignedSlice<A8>

impl<'_> SerializeTo<Variant> for &'_ Variant[src]

impl<M: Marker, T: SerializeTo<M::Type>> SerializeTo<Variant> for VariantWrap<M, T>[src]

impl ToOwned for Variant[src]

type Owned = Box<Self>

The resulting type after obtaining ownership.

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.