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:
183183
184184``` rust,ignore
185185let 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);
187188# result.unwrap(); // ignore the error
188189```
189190
190191Here’s the error:
191192
192193``` text
193194error: 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+ ^~~~~~~~~~
197197```
198198
199199We need to ` use ` the ` Write ` trait first:
@@ -202,7 +202,8 @@ We need to `use` the `Write` trait first:
202202use std::io::Write;
203203
204204let 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);
206207# result.unwrap(); // ignore the error
207208```
208209
You can’t perform that action at this time.
0 commit comments