@@ -14,25 +14,6 @@ use mem;
1414use intrinsics;
1515use ptr:: copy_nonoverlapping_memory;
1616
17- /// Casts the value at `src` to U. The two types must have the same length.
18- #[ inline]
19- pub unsafe fn transmute_copy < T , U > ( src : & T ) -> U {
20- let mut dest: U = mem:: uninit ( ) ;
21- let dest_ptr: * mut u8 = transmute ( & mut dest) ;
22- let src_ptr: * u8 = transmute ( src) ;
23- copy_nonoverlapping_memory ( dest_ptr, src_ptr, mem:: size_of :: < U > ( ) ) ;
24- dest
25- }
26-
27- /**
28- * Move a thing into the void
29- *
30- * The forget function will take ownership of the provided value but neglect
31- * to run any required cleanup or memory-management operations on it.
32- */
33- #[ inline]
34- pub unsafe fn forget < T > ( thing : T ) { intrinsics:: forget ( thing) ; }
35-
3617/**
3718 * Transform a value of one type into a value of another type.
3819 * Both types must have the same size and alignment.
@@ -51,6 +32,25 @@ pub unsafe fn transmute<L, G>(thing: L) -> G {
5132 intrinsics:: transmute ( thing)
5233}
5334
35+ /**
36+ * Move a thing into the void
37+ *
38+ * The forget function will take ownership of the provided value but neglect
39+ * to run any required cleanup or memory-management operations on it.
40+ */
41+ #[ inline]
42+ pub unsafe fn forget < T > ( thing : T ) { intrinsics:: forget ( thing) ; }
43+
44+ /// Casts the value at `src` to U. The two types must have the same length.
45+ #[ inline]
46+ pub unsafe fn transmute_copy < T , U > ( src : & T ) -> U {
47+ let mut dest: U = mem:: uninit ( ) ;
48+ let dest_ptr: * mut u8 = transmute ( & mut dest) ;
49+ let src_ptr: * u8 = transmute ( src) ;
50+ copy_nonoverlapping_memory ( dest_ptr, src_ptr, mem:: size_of :: < U > ( ) ) ;
51+ dest
52+ }
53+
5454/// Coerce an immutable reference to be mutable.
5555#[ inline]
5656#[ deprecated="casting &T to &mut T is undefined behaviour: use Cell<T>, RefCell<T> or Unsafe<T>" ]
0 commit comments