about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2016-04-17 17:50:34 +0530
committerManish Goregaokar <manishsmail@gmail.com>2016-04-17 17:50:34 +0530
commit43c23e5ebab1827540afda8d5e7079686addedff (patch)
tree1b80e85272e85fc474ce1aab318106c573d9050e
parent5fc8065ef269d1d4e4d8fe4134dcd17c5b9407fb (diff)
parent6c93c92ba7cdc5b8b907cfd0642e0909bcf6857c (diff)
downloadrust-43c23e5ebab1827540afda8d5e7079686addedff.tar.gz
rust-43c23e5ebab1827540afda8d5e7079686addedff.zip
Rollup merge of #33032 - kindlychung:patch-3, r=Manishearth
Update casting-between-types.md
-rw-r--r--src/doc/book/casting-between-types.md13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/doc/book/casting-between-types.md b/src/doc/book/casting-between-types.md
index 7d03d2991ab..7056a6c0f17 100644
--- a/src/doc/book/casting-between-types.md
+++ b/src/doc/book/casting-between-types.md
@@ -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
+    }
 }
 ```