Struct zvariant::OwnedValue[][src]

pub struct OwnedValue(_);

Owned Value

Methods from Deref<Target = Value<'static>>

pub fn value_signature(&self) -> Signature<'_>[src]

Get the signature of the enclosed value.

pub fn downcast_ref<T>(&'a self) -> Option<&'a T> where
    T: ?Sized,
    &'a T: TryFrom<&'a Value<'a>>, 
[src]

Try to get a reference to the underlying type T.

Same as downcast except it doesn’t consume self and get a reference to the underlying value.

Examples

use std::convert::TryFrom;
use zvariant::{Result, Value};

fn value_vec_to_type_vec<'a, T>(values: &'a Vec<Value<'a>>) -> Result<Vec<&'a T>>
where
    &'a T: TryFrom<&'a Value<'a>>,
{
    let mut res = vec![];
    for value in values.into_iter() {
        res.push(value.downcast_ref().unwrap());
    }

    Ok(res)
}

// Let's try u32 values first
let v = vec![Value::U32(42), Value::U32(43)];
let v = value_vec_to_type_vec::<u32>(&v).unwrap();
assert_eq!(*v[0], 42);
assert_eq!(*v[1], 43);

// Now try Value values
let v = vec![Value::new(Value::U32(42)), Value::new(Value::U32(43))];
let v = value_vec_to_type_vec::<Value>(&v).unwrap();
assert_eq!(*v[0], Value::U32(42));
assert_eq!(*v[1], Value::U32(43));

Trait Implementations

impl Clone for OwnedValue[src]

impl Debug for OwnedValue[src]

impl Deref for OwnedValue[src]

type Target = Value<'static>

The resulting type after dereferencing.

impl<'de> Deserialize<'de> for OwnedValue[src]

impl<'a> From<&'_ Value<'a>> for OwnedValue[src]

impl<'a> From<Value<'a>> for OwnedValue[src]

impl PartialEq<OwnedValue> for OwnedValue[src]

impl Serialize for OwnedValue[src]

impl StructuralPartialEq for OwnedValue[src]

impl<'a> TryFrom<&'a OwnedValue> for &'a str[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a OwnedValue> for &'a Signature<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a OwnedValue> for &'a ObjectPath<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a OwnedValue> for &'a Array<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a OwnedValue> for &'a Dict<'a, 'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a OwnedValue> for &'a Structure<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a OwnedValue> for Fd[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<OwnedValue> for Signature<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<OwnedValue> for OwnedSignature[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<OwnedValue> for ObjectPath<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<OwnedValue> for OwnedObjectPath[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<OwnedValue> for Array<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<OwnedValue> for Dict<'a, 'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<OwnedValue> for Structure<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<OwnedValue> for Fd[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> Type for OwnedValue[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.