#dynamic

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

#2339 in Rust patterns

Download history 120/week @ 2024-12-16 3/week @ 2024-12-23 24/week @ 2024-12-30 63/week @ 2025-01-06 136/week @ 2025-01-13 101/week @ 2025-01-20 62/week @ 2025-01-27 140/week @ 2025-02-03 116/week @ 2025-02-10 93/week @ 2025-02-17 94/week @ 2025-02-24 105/week @ 2025-03-03 154/week @ 2025-03-10 149/week @ 2025-03-17 120/week @ 2025-03-24 99/week @ 2025-03-31

522 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