Struct dynamic::Dynamic
[−]
[src]
pub struct Dynamic { /* fields omitted */ }
A dynamically typed value.
Differs from Any
in that it pre-computes type information at
creation-time, so that downcasting and other queries to the type
information can be implemented without virtual calls.
Not Sized, since the size of the type is determined at runtime, so must be
used behind a pointer (e.g. &Dynamic
, Box<Dynamic>
, etc.)
Methods
impl Dynamic
[src]
fn new<T: Any>(val: T) -> Box<Dynamic>
Create a new, heap-allocated Dynamic value containing the given value.
The resulting Dynamic
can be downcasted back to a T
.
fn from_ref<T: Any>(val: &Described<T>) -> &Dynamic
Create a new, immutable Dynamic value from the given described reference.
The resulting Dynamic
can be downcasted back to a T
.
fn from_mut<T: Any>(val: &mut Described<T>) -> &mut Dynamic
Create a new, mutable Dynamic value from the given described reference.
The resulting Dynamic
can be downcasted back to a T
.
fn id(&self) -> TypeId
Read the type id for the contained value.
fn is<T: Any>(&self) -> bool
Check if the contained type is a T
.
fn downcast<T: Any>(self: Box<Self>) -> Result<Box<Described<T>>, Box<Self>>
If the contained value is a T
, downcast back to it.
If the value is not a T
, returns Err(self)
.
fn downcast_ref<T: Any>(&self) -> Option<&T>
If the contained value is a T
, get an immutable reference to it.
fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
If the contained value is a T
, get a mutable reference to it.