Skip to content

Commit 99b1993

Browse files
committed
Simplify data functions
1 parent 8aabdda commit 99b1993

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,24 @@
55
//!
66
//! Unsafe helpers for working with raw TraitObjects.
77
8-
use std::mem;
9-
108
/// Get the data pointer from this trait object.
119
///
1210
/// Highly unsafe, as there is no information about the type of the data.
1311
pub unsafe fn data<T: ?Sized>(val: *const T) -> *const () {
14-
*mem::transmute::<*const *const T, *const *const ()>(&val)
12+
val as *const ()
1513
}
1614

1715
/// Get the data pointer from this trait object, mutably.
1816
///
1917
/// Highly unsafe, as there is no information about the type of the data.
20-
pub unsafe fn data_mut<T: ?Sized>(mut val: *mut T) -> *mut () {
21-
*mem::transmute::<*mut *mut T, *mut *mut ()>(&mut val)
18+
pub unsafe fn data_mut<T: ?Sized>(val: *mut T) -> *mut () {
19+
val as *mut ()
2220
}
2321

2422
#[test]
2523
fn test_simple() {
2624
let x = &7 as &Send;
27-
unsafe { assert!(&7 == mem::transmute::<_, &i32>(data(x))) };
25+
unsafe { assert!(&7 == std::mem::transmute::<_, &i32>(data(x))) };
2826
}
2927

3028
/// A trait implemented for all trait objects.

0 commit comments

Comments
 (0)