#any #unsafe #unchecked #trait-objects #runtime #type #traits

unsafe-any

Traits and implementations for unchecked downcasting

12 releases

Uses old Rust 2015

0.4.2 May 25, 2017
0.4.1 Apr 23, 2015
0.3.0 Apr 18, 2015
0.2.5 Apr 18, 2015
0.1.1 Nov 28, 2014
Download history 8580/week @ 2020-12-25 13863/week @ 2021-01-01 15330/week @ 2021-01-08 14317/week @ 2021-01-15 16890/week @ 2021-01-22 18488/week @ 2021-01-29 17682/week @ 2021-02-05 17669/week @ 2021-02-12 16165/week @ 2021-02-19 20225/week @ 2021-02-26 18365/week @ 2021-03-05 15977/week @ 2021-03-12 16206/week @ 2021-03-19 16005/week @ 2021-03-26 16620/week @ 2021-04-02 13996/week @ 2021-04-09

66,731 downloads per month
Used in 263 crates (10 directly)

MIT license

7KB
87 lines

Unsafe-Any Build Status

Convenience traits for unsafe downcasting from trait objects to concrete types.

Overview

This crate defines two new traits UncheckedAnyDowncast and UncheckedAnyMutDowncast, which define methods for downcasting to any type that implements Any from implemented trait objects.

It also defines two convenience implementations of these traits for &'a Any and &'a mut Any, which are the most common trait objects that you might downcast from.

Example:

let a = box 7u as Box<Any>;
unsafe { assert_eq!(*a.downcast_ref_unchecked::<uint>(), 7u); }

License

MIT


lib.rs:

Traits for unsafe downcasting from trait objects to & or &mut references of concrete types. These should only be used if you are absolutely certain of the type of the data in said trait object - there be dragons etc.

Originally inspired by https://github.com/chris-morgan/anymap and the implementation of std::any::Any.

Dependencies

~7KB