Crates.io | dynamic |
lib.rs | dynamic |
version | 0.2.1 |
source | src |
created_at | 2016-02-15 04:43:16.742061 |
updated_at | 2016-02-15 05:03:48.420497 |
description | A dyanmically typed value with fast downcasting. |
homepage | |
repository | https://github.com/reem/rust-dynamic.git |
max_upload_size | |
id | 4179 |
size | 7,182 |
A dyanmically typed value with fast downcasting.
Provides a Dynamic
type, which contains a dynamically typed value. Dynamic
is similar to Any
from std::any::Any
, except that downcasting does not
involve any virtual calls since the TypeId
of the contained value is pre-computed.
extern crate dynamic;
use dynamic::Dynamic;
fn main() {
// Create a new Dynamic value.
let x = Dynamic::new(100usize);
// If we try to downcast to the wrong type it will not work.
assert_eq!(x.downcast_ref::<i32>(), None);
// If we downcast to the right type, we get access.
assert_eq!(x.downcast_ref::<usize>(), Some(&100usize));
}
Use the crates.io repository; add this to your Cargo.toml
along
with the rest of your dependencies:
[dependencies]
dynamic = "0.2"
Jonathan Reem is the primary author and maintainer of dynamic.
MIT