File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -183,17 +183,17 @@ won’t have its methods:
183
183
184
184
``` rust,ignore
185
185
let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt");
186
- let result = f.write("whatever".as_bytes());
186
+ let buf = b"whatever"; // byte string literal. buf: &[u8; 8]
187
+ let result = f.write(buf);
187
188
# result.unwrap(); // ignore the error
188
189
```
189
190
190
191
Here’s the error:
191
192
192
193
``` text
193
194
error: type `std::fs::File` does not implement any method in scope named `write`
194
-
195
- let result = f.write("whatever".as_bytes());
196
- ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
195
+ let result = f.write(buf);
196
+ ^~~~~~~~~~
197
197
```
198
198
199
199
We need to ` use ` the ` Write ` trait first:
@@ -202,7 +202,8 @@ We need to `use` the `Write` trait first:
202
202
use std::io::Write;
203
203
204
204
let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt");
205
- let result = f.write("whatever".as_bytes());
205
+ let buf = b"whatever";
206
+ let result = f.write(buf);
206
207
# result.unwrap(); // ignore the error
207
208
```
208
209
You can’t perform that action at this time.
0 commit comments