# 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 Deref for OwnedValue[src]

#### type Target = Value<'static>

The resulting type after dereferencing.

### 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.

## Blanket Implementations

### 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.