Struct zvariant::OwnedValue
source · pub struct OwnedValue(_);
Expand description
Owned Value
Methods from Deref<Target = Value<'static>>§
sourcepub fn to_owned(&self) -> OwnedValue
pub fn to_owned(&self) -> OwnedValue
Create an owned version of self
.
Ideally, we should implement std::borrow::ToOwned
trait for Value
, but that’s
implemented generically for us through impl<T: Clone> ToOwned for T
and it’s not what we
need/want.
sourcepub fn value_signature(&self) -> Signature<'_>
pub fn value_signature(&self) -> Signature<'_>
Get the signature of the enclosed value.
sourcepub fn downcast_ref<T>(&'a self) -> Option<&'a T>where
T: ?Sized,
&'a T: TryFrom<&'a Value<'a>>,
pub fn downcast_ref<T>(&'a self) -> Option<&'a T>where T: ?Sized, &'a T: TryFrom<&'a Value<'a>>,
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§
source§impl Clone for OwnedValue
impl Clone for OwnedValue
source§fn clone(&self) -> OwnedValue
fn clone(&self) -> OwnedValue
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for OwnedValue
impl Debug for OwnedValue
source§impl Deref for OwnedValue
impl Deref for OwnedValue
source§impl<'de> Deserialize<'de> for OwnedValue
impl<'de> Deserialize<'de> for OwnedValue
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<'o> From<&'o OwnedValue> for Value<'o>
impl<'o> From<&'o OwnedValue> for Value<'o>
source§fn from(v: &'o OwnedValue) -> Value<'o>
fn from(v: &'o OwnedValue) -> Value<'o>
Converts to this type from the input type.
source§impl<'a> From<&Value<'a>> for OwnedValue
impl<'a> From<&Value<'a>> for OwnedValue
source§impl<'a> From<Array<'a>> for OwnedValue
impl<'a> From<Array<'a>> for OwnedValue
source§impl<'a> From<Dict<'a, 'a>> for OwnedValue
impl<'a> From<Dict<'a, 'a>> for OwnedValue
source§impl<'a> From<Fd> for OwnedValue
impl<'a> From<Fd> for OwnedValue
source§impl<K, V, H> From<HashMap<K, V, H>> for OwnedValuewhere
K: Type + Into<Value<'static>> + Hash + Eq,
V: Type + Into<Value<'static>>,
H: BuildHasher + Default,
impl<K, V, H> From<HashMap<K, V, H>> for OwnedValuewhere K: Type + Into<Value<'static>> + Hash + Eq, V: Type + Into<Value<'static>>, H: BuildHasher + Default,
source§impl<'a> From<Maybe<'a>> for OwnedValue
impl<'a> From<Maybe<'a>> for OwnedValue
source§impl<'a> From<ObjectPath<'a>> for OwnedValue
impl<'a> From<ObjectPath<'a>> for OwnedValue
source§fn from(v: ObjectPath<'a>) -> Self
fn from(v: ObjectPath<'a>) -> Self
Converts to this type from the input type.
source§impl From<OwnedValue> for Value<'static>
impl From<OwnedValue> for Value<'static>
source§fn from(v: OwnedValue) -> Value<'static>
fn from(v: OwnedValue) -> Value<'static>
Converts to this type from the input type.
source§impl<'a> From<Signature<'a>> for OwnedValue
impl<'a> From<Signature<'a>> for OwnedValue
source§impl<'a> From<Str<'a>> for OwnedValue
impl<'a> From<Str<'a>> for OwnedValue
source§impl<'a> From<Structure<'a>> for OwnedValue
impl<'a> From<Structure<'a>> for OwnedValue
source§impl<'a> From<Value<'a>> for OwnedValue
impl<'a> From<Value<'a>> for OwnedValue
source§impl<'a> From<bool> for OwnedValue
impl<'a> From<bool> for OwnedValue
source§impl<'a> From<f64> for OwnedValue
impl<'a> From<f64> for OwnedValue
source§impl<'a> From<i16> for OwnedValue
impl<'a> From<i16> for OwnedValue
source§impl<'a> From<i32> for OwnedValue
impl<'a> From<i32> for OwnedValue
source§impl<'a> From<i64> for OwnedValue
impl<'a> From<i64> for OwnedValue
source§impl<'a> From<u16> for OwnedValue
impl<'a> From<u16> for OwnedValue
source§impl<'a> From<u32> for OwnedValue
impl<'a> From<u32> for OwnedValue
source§impl<'a> From<u64> for OwnedValue
impl<'a> From<u64> for OwnedValue
source§impl<'a> From<u8> for OwnedValue
impl<'a> From<u8> for OwnedValue
source§impl PartialEq<OwnedValue> for OwnedValue
impl PartialEq<OwnedValue> for OwnedValue
source§fn eq(&self, other: &OwnedValue) -> bool
fn eq(&self, other: &OwnedValue) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.