1 stable release

Uses old Rust 2015

1.0.0 Sep 3, 2022

#541 in Rust patterns

Download history 27/week @ 2022-08-31 17/week @ 2022-09-07 7/week @ 2022-09-14 6/week @ 2022-09-21 9/week @ 2022-09-28 295/week @ 2022-10-05 6105/week @ 2022-10-12 8024/week @ 2022-10-19 9325/week @ 2022-10-26 9055/week @ 2022-11-02 9937/week @ 2022-11-09 8962/week @ 2022-11-16 9760/week @ 2022-11-23 7996/week @ 2022-11-30

38,485 downloads per month
Used in 4 crates (via typemap-ors)

MIT license

8KB
101 lines

unsafe-any-ors CI

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