Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value {
Show 16 variants Bool(bool), U8(u8), I16(i16), U16(u16), I32(i32), U32(u32), I64(i64), U64(u64), F64(f64), String(String), ObjectPath(ObjectPathBuf), Signature(SignatureBuf), Array { element: SignatureBuf, values: Vec<Value>, }, Dict { key: SignatureBuf, value: SignatureBuf, entries: Vec<(Value, Value)>, }, Struct(Vec<Value>), Variant(Box<Value>),
}
Expand description

A D-Bus value whose type is only known at runtime.

This is what a v in a signature is decoded into, and holds the value that was inside the variant rather than the variant itself. A Value::Variant is therefore only produced for a variant nested inside another one.

§Examples

use std::collections::HashMap;

use tokio_dbus_runtime::Value;

let mut hints = HashMap::new();
hints.insert(String::from("urgency"), Value::U8(2));
hints.insert(String::from("category"), Value::String("device".into()));

assert_eq!(hints["urgency"].signature()?, "y");
assert_eq!(hints["category"].signature()?, "s");

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Bool(bool)

A boolean.

§

U8(u8)

A single byte.

§

I16(i16)

A signed 16-bit integer.

§

U16(u16)

An unsigned 16-bit integer.

§

I32(i32)

A signed 32-bit integer.

§

U32(u32)

An unsigned 32-bit integer.

§

I64(i64)

A signed 64-bit integer.

§

U64(u64)

An unsigned 64-bit integer.

§

F64(f64)

A 64-bit floating point number.

§

String(String)

A string.

§

ObjectPath(ObjectPathBuf)

An object path.

§

Signature(SignatureBuf)

A signature.

§

Array

An array.

The signature of the element type is carried along, since it cannot be recovered from the values when the array is empty.

Fields

§element: SignatureBuf

The type of each element.

§values: Vec<Value>

The elements.

§

Dict

A dictionary, which on the wire is an array of key and value pairs.

Fields

§key: SignatureBuf

The type of each key.

§value: SignatureBuf

The type of each value.

§entries: Vec<(Value, Value)>

The entries, in the order they appeared.

§

Struct(Vec<Value>)

A struct.

§

Variant(Box<Value>)

A variant nested inside of another value.

Implementations§

Source§

impl Value

Source

pub fn array(element: &str) -> Result<Self>

Construct an empty array of the given element type.

§Examples
use tokio_dbus_runtime::Value;

let value = Value::array("(iiay)")?;
assert_eq!(value.signature()?, "a(iiay)");
Source

pub fn signature(&self) -> Result<SignatureBuf>

The signature of this value.

§Examples
use tokio_dbus_runtime::Value;

let value = Value::Struct(vec![Value::I32(1), Value::String("hi".into())]);
assert_eq!(value.signature()?, "(is)");

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

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

impl Decode for Value

Source§

const ALIGNMENT: Alignment = Alignment::BYTE

The alignment of the encoded value.
Source§

fn decode(body: &mut Body<'_>) -> Result<Self>

Read one value from the body.
Source§

impl Display for Value

Source§

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

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

impl Encode for Value

Source§

const ALIGNMENT: Alignment = Alignment::BYTE

The alignment of the encoded value, which the containers this value is nested inside need in order to pad correctly.
Source§

fn encode(&self, raw: &mut Raw<'_>)

Write the value, without writing its signature.
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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.