Skip to content

Commit

Permalink
Rollup merge of rust-lang#33032 - kindlychung:patch-3, r=Manishearth
Browse files Browse the repository at this point in the history
Update casting-between-types.md
  • Loading branch information
Manishearth committed Apr 17, 2016
2 parents 5fc8065 + 6c93c92 commit 43c23e5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/doc/book/casting-between-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,15 @@ Rust lets us:
```rust
use std::mem;

unsafe {
let a = [0u8, 0u8, 0u8, 0u8];

let b = mem::transmute::<[u8; 4], u32>(a);
fn main() {
unsafe {
let a = [0u8, 1u8, 0u8, 0u8];
let b = mem::transmute::<[u8; 4], u32>(a);
println!("{}", b); // 256
// or, more concisely:
let c: u32 = mem::transmute(a);
println!("{}", c); // 256
}
}
```

Expand Down

0 comments on commit 43c23e5

Please sign in to comment.