]> git.lizzy.rs Git - rust.git/blob - src/docs/transmute_num_to_bytes.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / transmute_num_to_bytes.txt
1 ### What it does
2 Checks for transmutes from a number to an array of `u8`
3
4 ### Why this is bad?
5 Transmutes are dangerous and error-prone, whereas `to_ne_bytes`
6 is intuitive and safe.
7
8 ### Example
9 ```
10 unsafe {
11     let x: [u8; 8] = std::mem::transmute(1i64);
12 }
13
14 // should be
15 let x: [u8; 8] = 0i64.to_ne_bytes();
16 ```