pub struct Value<'val, 'ty>(/* private fields */)
where
'ty: 'val;Expand description
A container for a type-erased value.
Value is, in essence, a smart-pointer that can hold any reflected type. It is slightly larger than a standard fat-pointer, since it contains metadata about the type it contains.
Implementations§
Source§impl<'val, 'ty> Value<'val, 'ty>
impl<'val, 'ty> Value<'val, 'ty>
Sourcepub fn from_vec(s: &'val (dyn VecInstance<'ty> + 'ty)) -> Value<'val, 'ty>
pub fn from_vec(s: &'val (dyn VecInstance<'ty> + 'ty)) -> Value<'val, 'ty>
Sourcepub fn from_struct(s: &'val (dyn StructInstance<'ty> + 'ty)) -> Value<'val, 'ty>
pub fn from_struct(s: &'val (dyn StructInstance<'ty> + 'ty)) -> Value<'val, 'ty>
Creates a Value from a reflected struct
Sourcepub fn from_enum(s: &'val (dyn EnumInstance<'ty> + 'ty)) -> Value<'val, 'ty>
pub fn from_enum(s: &'val (dyn EnumInstance<'ty> + 'ty)) -> Value<'val, 'ty>
Creates a Value from a reflected enum
Sourcepub fn from_option(s: &'val (dyn OptionInstance<'ty> + 'ty)) -> Value<'val, 'ty>
pub fn from_option(s: &'val (dyn OptionInstance<'ty> + 'ty)) -> Value<'val, 'ty>
Creates a Value from a reflected option
Sourcepub fn borrow<'b, T: FromValue<'val, 'ty>>(&'b self) -> Option<T>where
'val: 'b,
'ty: 'b,
pub fn borrow<'b, T: FromValue<'val, 'ty>>(&'b self) -> Option<T>where
'val: 'b,
'ty: 'b,
Borrows the value as an underlying type. This will return None,
when the runtime type-check fails
Sourcepub fn into<T: FromValue<'val, 'ty> + 'ty>(self) -> Option<T>
pub fn into<T: FromValue<'val, 'ty> + 'ty>(self) -> Option<T>
Consumes the Value and returns the internal T.
This only works for types that implement FromValue, which are generally primitives
that implement Copy.
Sourcepub fn as_reflected_vec(&self) -> Option<&'val (dyn VecInstance<'ty> + 'ty)>
pub fn as_reflected_vec(&self) -> Option<&'val (dyn VecInstance<'ty> + 'ty)>
Attempts to cast Value to a VecInstance
Sourcepub fn as_reflected_struct(
&self,
) -> Option<&'val (dyn StructInstance<'ty> + 'ty)>
pub fn as_reflected_struct( &self, ) -> Option<&'val (dyn StructInstance<'ty> + 'ty)>
Attempts to cast Value to a StructInstance
Sourcepub fn as_reflected_enum(&'val self) -> Option<&(dyn EnumInstance<'ty> + 'ty)>
pub fn as_reflected_enum(&'val self) -> Option<&(dyn EnumInstance<'ty> + 'ty)>
Attempts to cast Value to a EnumInstance
Sourcepub fn as_reflected_option(
&'val self,
) -> Option<&(dyn OptionInstance<'ty> + 'ty)>
pub fn as_reflected_option( &'val self, ) -> Option<&(dyn OptionInstance<'ty> + 'ty)>
Attempts to cast Value to a OptionInstance
Sourcepub fn to_owned(&self) -> OwnedValue<'ty>
pub fn to_owned(&self) -> OwnedValue<'ty>
Clones the underlying value, and returns a OwnedValue