#[repr(C)]pub struct Value(_, _);
Expand description
A generic value capable of carrying various types.
Once created the type of the value can’t be changed.
Some types (e.g. String
and objects) support None
values while others
(e.g. numeric types) don’t.
Value
does not implement the Send
trait, but SendValue
can be
used instead.
See the module documentation for more details.
Implementations
sourceimpl Value
impl Value
sourcepub fn downcast<'a, T: FromValueOptional<'a> + SetValue>(
self
) -> Result<TypedValue<T>, Self>
pub fn downcast<'a, T: FromValueOptional<'a> + SetValue>(
self
) -> Result<TypedValue<T>, Self>
Tries to downcast to a TypedValue
.
Returns Ok(TypedValue<T>)
if the value carries a type corresponding
to T
and Err(self)
otherwise.
sourcepub fn downcast_ref<'a, T: FromValueOptional<'a> + SetValue>(
&self
) -> Option<&TypedValue<T>>
pub fn downcast_ref<'a, T: FromValueOptional<'a> + SetValue>(
&self
) -> Option<&TypedValue<T>>
Tries to downcast to a &TypedValue
.
Returns Some(&TypedValue<T>)
if the value carries a type corresponding
to T
and None
otherwise.
sourcepub fn get<'a, T: FromValueOptional<'a>>(&'a self) -> Option<T>
pub fn get<'a, T: FromValueOptional<'a>>(&'a self) -> Option<T>
Tries to get a value of type T
.
Returns Some
if the type is correct and the value is not None
.
This function doesn’t distinguish between type mismatches and correctly
typed None
values. Use downcast
or is
for that.
sourcepub fn is<'a, T: FromValueOptional<'a> + SetValue>(&self) -> bool
pub fn is<'a, T: FromValueOptional<'a> + SetValue>(&self) -> bool
Returns true
if the type of the value corresponds to T
or is a sub-type of T
.
sourcepub fn type_transformable(src: Type, dst: Type) -> bool
pub fn type_transformable(src: Type, dst: Type) -> bool
Returns whether Value
s of type src
can be transformed to type dst
.