From 6c93c92ba7cdc5b8b907cfd0642e0909bcf6857c Mon Sep 17 00:00:00 2001 From: Kaiyin Zhong Date: Sat, 16 Apr 2016 18:04:27 +0200 Subject: [PATCH] Update casting-between-types.md --- src/doc/book/casting-between-types.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/doc/book/casting-between-types.md b/src/doc/book/casting-between-types.md index 7d03d2991abdc..7056a6c0f1708 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 + } } ```