Debian Codegraph @

src/lib.rs

raw symbols SCIP
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 data<T: ?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_mut<T: ?Sized>(val: *mut T) -> *mut () {
19 val as *mut ()
20 }
21
22 #[test]
23 fn test_simple() {
24 let x = &7 as &dyn Send;
25 unsafe { assert!(&7 == std::mem::transmute::<_, &i32>(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 Trait {}
32
33 mod impls;