Use if-let in std::result documentation
This takes an opportunity to show yet-another-way of dealing with Results and matching.
This commit is contained in:
parent
064c21efd2
commit
1217007c83
1 changed files with 4 additions and 6 deletions
|
|
@ -178,13 +178,11 @@
|
|||
//! fn write_info(info: &Info) -> Result<(), IoError> {
|
||||
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
|
||||
//! // Early return on error
|
||||
//! match file.write_line(format!("name: {}", info.name).as_slice()) {
|
||||
//! Ok(_) => (),
|
||||
//! Err(e) => return Err(e)
|
||||
//! if let Err(e) = file.write_line(format!("name: {}", info.name).as_slice()) {
|
||||
//! return Err(e)
|
||||
//! }
|
||||
//! match file.write_line(format!("age: {}", info.age).as_slice()) {
|
||||
//! Ok(_) => (),
|
||||
//! Err(e) => return Err(e)
|
||||
//! if let Err(e) = file.write_line(format!("age: {}", info.age).as_slice()) {
|
||||
//! return Err(e)
|
||||
//! }
|
||||
//! return file.write_line(format!("rating: {}", info.rating).as_slice());
|
||||
//! }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue