1
Fork 0

Update casting-between-types.md

This commit is contained in:
Kaiyin Zhong 2016-04-16 18:04:27 +02:00
parent 6fa61b810d
commit 6c93c92ba7

View file

@ -165,10 +165,15 @@ Rust lets us:
```rust ```rust
use std::mem; use std::mem;
unsafe { fn main() {
let a = [0u8, 0u8, 0u8, 0u8]; unsafe {
let a = [0u8, 1u8, 0u8, 0u8];
let b = mem::transmute::<[u8; 4], u32>(a); let b = mem::transmute::<[u8; 4], u32>(a);
println!("{}", b); // 256
// or, more concisely:
let c: u32 = mem::transmute(a);
println!("{}", c); // 256
}
} }
``` ```