Skip to content

Commit 6c93c92

Browse files
committed
Update casting-between-types.md
1 parent 6fa61b8 commit 6c93c92

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/doc/book/casting-between-types.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,15 @@ Rust lets us:
165165
```rust
166166
use std::mem;
167167

168-
unsafe {
169-
let a = [0u8, 0u8, 0u8, 0u8];
170-
171-
let b = mem::transmute::<[u8; 4], u32>(a);
168+
fn main() {
169+
unsafe {
170+
let a = [0u8, 1u8, 0u8, 0u8];
171+
let b = mem::transmute::<[u8; 4], u32>(a);
172+
println!("{}", b); // 256
173+
// or, more concisely:
174+
let c: u32 = mem::transmute(a);
175+
println!("{}", c); // 256
176+
}
172177
}
173178
```
174179

0 commit comments

Comments
 (0)