#downcasts #dynamically-typed #value

dynamic

A dyanmically typed value with fast downcasting

3 unstable releases

Uses old Rust 2015

0.2.1 Feb 15, 2016
0.2.0 Feb 15, 2016
0.1.0 Feb 15, 2016

#20 in #downcasts

Download history 21/week @ 2026-01-18 12/week @ 2026-01-25 36/week @ 2026-02-01 2/week @ 2026-02-08 35/week @ 2026-02-15 23/week @ 2026-02-22 7/week @ 2026-03-01 3/week @ 2026-03-08 9/week @ 2026-03-15 21/week @ 2026-03-22 42/week @ 2026-03-29 73/week @ 2026-04-05 54/week @ 2026-04-12 12/week @ 2026-04-19 11/week @ 2026-04-26 44/week @ 2026-05-03

131 downloads per month
Used in 3 crates

MIT license

7KB
113 lines

dynamic

A dyanmically typed value with fast downcasting.

Documentation

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.

Example

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));
}

Usage

Use the crates.io repository; add this to your Cargo.toml along with the rest of your dependencies:

[dependencies]
dynamic = "0.2"

Author

Jonathan Reem is the primary author and maintainer of dynamic.

License

MIT

Dependencies

~14KB