pub enum Value {
}Expand description
A dynamically-typed GVariant value.
The representation is canonical with respect to a Type:
- byte arrays (
ay) areBytes, neverArrayofByte; - dict entries are two-element
Tuples; - a
Variantcarries the child’s type, since the serialized form embeds the child’s signature. - a double is held as its IEEE-754 bit pattern, so a value compares by the bytes it serializes to.
- an object path (
o) and a signature (g) areStr, and a handle (h) isI32; theTypestates which of the pair a value carries.
Variants§
Bool(bool)
b.
Byte(u8)
y.
I16(i16)
n.
U16(u16)
q.
I32(i32)
i, and the folded h.
U32(u32)
u.
I64(i64)
x.
U64(u64)
t.
Double(u64)
The IEEE-754 bit pattern of a d value. Build one with
Value::double.
Str(String)
s, and the folded o and g.
Bytes(Vec<u8>)
ay, held as its bytes rather than as an array of Value::Byte.
Maybe(Option<Box<Value>>)
m<T>: the value it holds, or None for nothing.
Array(Vec<Value>)
a<T>: the elements, in order.
Tuple(Vec<Value>)
(...), and the folded dict entry, which is a two-element tuple.
Variant(Box<(Type, Value)>)
v: the child’s type and the child.
Implementations§
Source§impl Value
impl Value
Sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
The byte array this value holds, or None for any other type.
Sourcepub fn as_array(&self) -> Option<&[Value]>
pub fn as_array(&self) -> Option<&[Value]>
The array elements this value holds, or None for any other type.
Sourcepub fn as_strv(&self) -> Option<Vec<&str>>
pub fn as_strv(&self) -> Option<Vec<&str>>
The strings an array holds, or None for any other type. One element
that is not a string yields None for the whole array. The empty
array yields the empty list.
Sourcepub fn as_tuple(&self) -> Option<&[Value]>
pub fn as_tuple(&self) -> Option<&[Value]>
The tuple members this value holds, or None for any other type.
Sourcepub fn as_variant(&self) -> Option<(&Type, &Value)>
pub fn as_variant(&self) -> Option<(&Type, &Value)>
The child type and child value a variant holds, or None for any other type.
Sourcepub fn byteswapped(&self) -> Value
pub fn byteswapped(&self) -> Value
The same value with every multi-byte scalar byte-swapped, recursively, through arrays, tuples, dict entries, and the child of a variant.
This is GVariant’s own byte-order conversion. The on-disk format places its numeric fields in the variant already big-endian while the framing stays little-endian, so a value parsed from those bytes holds each numeric field byte-reversed, and one swap of the whole tree recovers the numbers the fields state. Booleans, bytes, and strings are unchanged.
Sourcepub fn dict_get(&self, key: &str) -> Option<&Value>
pub fn dict_get(&self, key: &str) -> Option<&Value>
Look up a key in a dictionary value (a{s?}): an array of two-element
tuples whose first member is the key string. Returns the value member of
the first entry whose key matches. Entries that are not {s?}-shaped are
skipped; a non-array self yields None.