| 1 | #![cfg_attr(test, deny(warnings))] |
| 2 | #![deny(missing_docs)] |
| 3 | |
| 4 | //! # traitobject |
| 5 | //! |
| 6 | //! Unsafe helpers for working with raw TraitObjects. |
| 7 | |
| 8 | /// Get the data pointer from this trait object. |
| 9 | /// |
| 10 | /// Highly unsafe, as there is no information about the type of the data. |
| 11 | pub unsafe fn datarust-analyzer cargo traitobject 0.1.1 data().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(val: *const T) -> *const () { |
| 12 | val as *const () |
| 13 | } |
| 14 | |
| 15 | /// Get the data pointer from this trait object, mutably. |
| 16 | /// |
| 17 | /// Highly unsafe, as there is no information about the type of the data. |
| 18 | pub unsafe fn data_mutrust-analyzer cargo traitobject 0.1.1 data_mut().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(val: *mut T) -> *mut () { |
| 19 | val as *mut () |
| 20 | } |
| 21 | |
| 22 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 23 | fn test_simplerust-analyzer cargo traitobject 0.1.1 test_simple().() { |
| 24 | let x = &7 as &dyn Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#; |
| 25 | unsafe { assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(&7 == stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().::<_, &i32>(datarust-analyzer cargo traitobject 0.1.1 data().(x))) }; |
| 26 | } |
| 27 | |
| 28 | /// A trait implemented for all trait objects. |
| 29 | /// |
| 30 | /// Implementations for all traits in std are provided. |
| 31 | pub unsafe trait Traitrust-analyzer cargo traitobject 0.1.1 Trait# {} |
| 32 | |
| 33 | mod implsrust-analyzer cargo traitobject 0.1.1 impls/; |