@@ -6,9 +6,10 @@ really can't emphasize that you should deeply think about finding Another Way
6
6
than the operations covered in this section. This is really, truly, the most
7
7
horribly unsafe thing you can do in Rust. The railguards here are dental floss.
8
8
9
- ` mem::transmute<T, U> ` takes a value of type ` T ` and reinterprets it to have
10
- type ` U ` . The only restriction is that the ` T ` and ` U ` are verified to have the
11
- same size. The ways to cause Undefined Behavior with this are mind boggling.
9
+ [ ` mem::transmute<T, U> ` ] [ transmute ] takes a value of type ` T ` and reinterprets
10
+ it to have type ` U ` . The only restriction is that the ` T ` and ` U ` are verified
11
+ to have the same size. The ways to cause Undefined Behavior with this are mind
12
+ boggling.
12
13
13
14
* First and foremost, creating an instance of * any* type with an invalid state
14
15
is going to cause arbitrary chaos that can't really be predicted.
@@ -23,13 +24,16 @@ same size. The ways to cause Undefined Behavior with this are mind boggling.
23
24
* Transmuting to a reference without an explicitly provided lifetime
24
25
produces an [ unbounded lifetime]
25
26
26
- ` mem::transmute_copy<T, U> ` somehow manages to be * even more* wildly unsafe than
27
- this. It copies ` size_of<U> ` bytes out of an ` &T ` and interprets them as a ` U ` .
28
- The size check that ` mem::transmute ` has is gone (as it may be valid to copy
29
- out a prefix), though it is Undefined Behavior for ` U ` to be larger than ` T ` .
27
+ [ ` mem::transmute_copy<T, U> ` ] [ transmute_copy ] somehow manages to be * even more*
28
+ wildly unsafe than this. It copies ` size_of<U> ` bytes out of an ` &T ` and
29
+ interprets them as a ` U ` . The size check that ` mem::transmute ` has is gone (as
30
+ it may be valid to copy out a prefix), though it is Undefined Behavior for ` U `
31
+ to be larger than ` T ` .
30
32
31
33
Also of course you can get most of the functionality of these functions using
32
34
pointer casts.
33
35
34
36
35
37
[ unbounded lifetime ] : unbounded-lifetimes.html
38
+ [ transmute ] : ../std/mem/fn.transmute.html
39
+ [ transmute_copy ] : ../std/mem/fn.transmute.html
0 commit comments