1 stable release
Uses old Rust 2015
1.0.0 | Sep 3, 2022 |
---|
#2005 in Rust patterns
163,367 downloads per month
Used in 7 crates
(via typemap-ors)
8KB
101 lines
unsafe-any-ors
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
~8KB