File tree Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ won’t have its methods:
247
247
[ write ] : ../std/io/trait.Write.html
248
248
249
249
``` rust,ignore
250
- let mut f = std::fs::File::open("foo.txt").ok(). expect("Couldn’t open foo.txt");
250
+ let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt");
251
251
let buf = b"whatever"; // byte string literal. buf: &[u8; 8]
252
252
let result = f.write(buf);
253
253
# result.unwrap(); // ignore the error
@@ -266,7 +266,7 @@ We need to `use` the `Write` trait first:
266
266
``` rust,ignore
267
267
use std::io::Write;
268
268
269
- let mut f = std::fs::File::open("foo.txt").ok(). expect("Couldn’t open foo.txt");
269
+ let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt");
270
270
let buf = b"whatever";
271
271
let result = f.write(buf);
272
272
# result.unwrap(); // ignore the error
Original file line number Diff line number Diff line change 117
117
//! warning (by default, controlled by the `unused_must_use` lint).
118
118
//!
119
119
//! You might instead, if you don't want to handle the error, simply
120
- //! panic, by converting to an `Option` with `ok`, then asserting
121
- //! success with `expect`. This will panic if the write fails, proving
122
- //! a marginally useful message indicating why:
120
+ //! assert success with `expect`. This will panic if the
121
+ //! write fails, providing a marginally useful message indicating why:
123
122
//!
124
123
//! ```{.no_run}
125
124
//! use std::fs::File;
126
125
//! use std::io::prelude::*;
127
126
//!
128
127
//! let mut file = File::create("valuable_data.txt").unwrap();
129
- //! file.write_all(b"important message").ok(). expect("failed to write message");
128
+ //! file.write_all(b"important message").expect("failed to write message");
130
129
//! ```
131
130
//!
132
131
//! You might also simply assert success:
You can’t perform that action at this time.
0 commit comments