Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/doc/trpl/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ 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
```

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(buf);
^~~~~~~~~~
```

We need to `use` the `Write` trait first:
Expand All @@ -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
```

Expand Down