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

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

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]

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

Get a static reference to the default value for this type. Read more

Cast slice to type Self. Read more

Formats the value using the given formatter. Read more

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

This method tests for !=.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more