[−][src]Struct gvariant::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]
AlignedSlice<A8>: AsAligned<<M::Type as AlignOf>::AlignOf>,
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]
impl AllBitPatternsValid for Variant
[src]
impl Cast for Variant
[src]
fn default_ref() -> &'static Self
[src]
fn try_from_aligned_slice(
slice: &AlignedSlice<Self::AlignOf>
) -> Result<&Self, WrongSize>
[src]
slice: &AlignedSlice<Self::AlignOf>
) -> Result<&Self, WrongSize>
fn try_from_aligned_slice_mut(
slice: &mut AlignedSlice<Self::AlignOf>
) -> Result<&mut Self, WrongSize>
[src]
slice: &mut AlignedSlice<Self::AlignOf>
) -> Result<&mut Self, WrongSize>
fn from_aligned_slice(slice: &AlignedSlice<Self::AlignOf>) -> &Self
[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.