Skip to content

Commit cd8dc17

Browse files
committed
---
yaml --- r: 150859 b: refs/heads/try2 c: e69bd81 h: refs/heads/master i: 150857: 2c2dee4 150855: 5640314 v: v3
1 parent 874d884 commit cd8dc17

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 46cb598efb5a6dc0bacb52411daa983f415e9865
8+
refs/heads/try2: e69bd81deca29f9adbf175760dddbaec9be3163d
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/result.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
//!
3636
//! fn parse_version(header: &[u8]) -> Result<Version, &'static str> {
3737
//! if header.len() < 1 {
38-
//! return Err("invalid header length");;
38+
//! return Err("invalid header length");
3939
//! }
4040
//! match header[0] {
4141
//! 1 => Ok(Version1),
@@ -77,18 +77,19 @@
7777
//! // Use `or_else` to handle the error.
7878
//! let bad_result: Result<int, int> = bad_result.or_else(|i| Ok(11));
7979
//!
80-
//! // Convert to an `Option` to call e.g. `unwrap`.
80+
//! // Consume the result and return the contents with `unwrap`.
8181
//! let final_awesome_result = good_result.ok().unwrap();
8282
//! ~~~
8383
//!
8484
//! # Results must be used
8585
//!
86-
//! A common problem with using return values to indicate errors
87-
//! is that it is easy to ignore the return value, thus failing
88-
//! to handle the error. By possessing the `#[must_use]` attribute,
89-
//! the compiler will warn when a `Result` type is ignored. This
90-
//! makes `Result` especially useful with functions that may
91-
//! encounter errors but don't otherwise return a useful value.
86+
//! A common problem with using return values to indicate errors is
87+
//! that it is easy to ignore the return value, thus failing to handle
88+
//! the error. Result is annotated with the #[must_use] attribute,
89+
//! which will cause the compiler to issue a warning when a Result
90+
//! value is ignored. This makes `Result` especially useful with
91+
//! functions that may encounter errors but don't otherwise return a
92+
//! useful value.
9293
//!
9394
//! Consider the `write_line` method defined for I/O types
9495
//! by the [`Writer`](../io/trait.Writer.html) trait:
@@ -126,28 +127,22 @@
126127
//! success with `expect`. This will fail if the write fails, proving
127128
//! a marginally useful message indicating why:
128129
//!
129-
//! ~~~
130-
//! # // not running this test because it creates a file
131-
//! # fn do_not_run_test() {
130+
//! ~~~no_run
132131
//! use std::io::{File, Open, Write};
133132
//!
134133
//! let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write);
135134
//! file.write_line("important message").ok().expect("failed to write message");
136135
//! drop(file);
137-
//! # }
138136
//! ~~~
139137
//!
140138
//! You might also simply assert success:
141139
//!
142-
//! ~~~
143-
//! # // not running this test because it creates a file
144-
//! # fn do_not_run_test() {
140+
//! ~~~no_run
145141
//! # use std::io::{File, Open, Write};
146142
//!
147143
//! # let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write);
148144
//! assert!(file.write_line("important message").is_ok());
149145
//! # drop(file);
150-
//! # }
151146
//! ~~~
152147
//!
153148
//! Or propagate the error up the call stack with `try!`:
@@ -215,10 +210,12 @@
215210
//! `Err` is returned early from the enclosing function. Its simple definition
216211
//! makes it clear:
217212
//!
218-
//! ~~~ignore
213+
//! ~~~
214+
//! # #![feature(macro_rules)]
219215
//! macro_rules! try(
220216
//! ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
221217
//! )
218+
//! # fn main() { }
222219
//! ~~~
223220
//!
224221
//! `try!` is imported by the prelude, and is available everywhere.

0 commit comments

Comments
 (0)