Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 15 variants Bool(bool), Byte(u8), I16(i16), U16(u16), I32(i32), U32(u32), I64(i64), U64(u64), Double(u64), Str(String), Bytes(Vec<u8>), Maybe(Option<Box<Value>>), Array(Vec<Value>), Tuple(Vec<Value>), Variant(Box<(Type, Value)>),
}
Expand description

A dynamically-typed GVariant value.

The representation is canonical with respect to a Type:

  • byte arrays (ay) are Bytes, never Array of Byte;
  • dict entries are two-element Tuples;
  • a Variant carries 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) are Str, and a handle (h) is I32; the Type states 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

Source

pub fn variant(ty: Type, value: Value) -> Value

Wrap value of type ty as a variant.

Source

pub fn double(value: f64) -> Value

A d value from a double.

Source

pub fn as_bool(&self) -> Option<bool>

The b this value holds, or None for any other type.

Source

pub fn as_byte(&self) -> Option<u8>

The y this value holds, or None for any other type.

Source

pub fn as_u32(&self) -> Option<u32>

The u this value holds, or None for any other type.

Source

pub fn as_u64(&self) -> Option<u64>

The t this value holds, or None for any other type.

Source

pub fn as_str(&self) -> Option<&str>

The string this value holds, or None for any other type.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

The byte array this value holds, or None for any other type.

Source

pub fn as_array(&self) -> Option<&[Value]>

The array elements this value holds, or None for any other type.

Source

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.

Source

pub fn as_tuple(&self) -> Option<&[Value]>

The tuple members this value holds, or None for any other type.

Source

pub fn as_variant(&self) -> Option<(&Type, &Value)>

The child type and child value a variant holds, or None for any other type.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for Value

Source§

impl From<&[u8]> for Value

Source§

fn from(v: &[u8]) -> Value

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(v: &str) -> Value

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(v: Vec<u8>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Value

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(v: u8) -> Value

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Value

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(v: u64) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.