#unsafe #ors #unsafe-any-ors

unsafe-any-ors

Traits and implementations for unchecked downcasting

1 stable release

Uses old Rust 2015

1.0.0 Sep 3, 2022

#43 in #unsafe

Download history 64208/week @ 2024-12-16 34826/week @ 2024-12-23 36195/week @ 2024-12-30 56548/week @ 2025-01-06 50389/week @ 2025-01-13 50199/week @ 2025-01-20 47821/week @ 2025-01-27 51156/week @ 2025-02-03 66507/week @ 2025-02-10 66261/week @ 2025-02-17 75798/week @ 2025-02-24 80762/week @ 2025-03-03 80902/week @ 2025-03-10 72252/week @ 2025-03-17 69119/week @ 2025-03-24 83385/week @ 2025-03-31

313,440 downloads per month
Used in 7 crates (via typemap-ors)

MIT license

8KB
101 lines

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.


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

Dependencies

~8KB