From 55c8bacc3a07dae23d79ab083822518da14ffdf9 Mon Sep 17 00:00:00 2001 From: peferron Date: Sat, 16 May 2015 17:01:25 -0700 Subject: [PATCH 1/2] Make error message consistent with source code The source code uses `"whatever".as_bytes()`, not `b"whatever"`. --- src/doc/trpl/traits.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 889205ad5d8b1..d22c9cba08267 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -192,8 +192,8 @@ Here’s the error: ```text error: type `std::fs::File` does not implement any method in scope named `write` -let result = f.write(b"whatever"); - ^~~~~~~~~~~~~~~~~~ +let result = f.write("whatever".as_bytes()); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` We need to `use` the `Write` trait first: From a10d243dd46e84813819cca140a72ad9fcff951d Mon Sep 17 00:00:00 2001 From: peferron Date: Sun, 17 May 2015 21:18:29 -0700 Subject: [PATCH 2/2] Use byte string literal syntax The byte string literal syntax `b"whatever"` is more idiomatic than `"whatever".as_bytes()`. --- src/doc/trpl/traits.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index d22c9cba08267..c82f0405598c7 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -183,7 +183,8 @@ won’t have its methods: ```rust,ignore let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt"); -let result = f.write("whatever".as_bytes()); +let buf = b"whatever"; // byte string literal. buf: &[u8; 8] +let result = f.write(buf); # result.unwrap(); // ignore the error ``` @@ -191,9 +192,8 @@ Here’s the error: ```text error: type `std::fs::File` does not implement any method in scope named `write` - -let result = f.write("whatever".as_bytes()); - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ +let result = f.write(buf); + ^~~~~~~~~~ ``` We need to `use` the `Write` trait first: @@ -202,7 +202,8 @@ We need to `use` the `Write` trait first: use std::io::Write; let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt"); -let result = f.write("whatever".as_bytes()); +let buf = b"whatever"; +let result = f.write(buf); # result.unwrap(); // ignore the error ```