Skip to content

Commit 30908c4

Browse files
aochagaviaalexcrichton
authored andcommitted
---
yaml --- r: 151582 b: refs/heads/try2 c: 85e34b2 h: refs/heads/master v: v3
1 parent 4e11338 commit 30908c4

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
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: 437338ab658d075b50538541541e3049a79f5911
8+
refs/heads/try2: 85e34b239672a5d8c0d4ef01fae06f6921de9591
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/option.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,23 @@
3030
//! of a value and take action, always accounting for the `None` case.
3131
//!
3232
//! ```
33-
//! # // FIXME This is not the greatest first example
34-
//! // cow_says contains the word "moo"
35-
//! let cow_says = Some("moo");
36-
//! // dog_says does not contain a value
37-
//! let dog_says: Option<&str> = None;
33+
//! fn divide(numerator: f64, denominator: f64) -> Option<f64> {
34+
//! if denominator == 0.0 {
35+
//! None
36+
//! } else {
37+
//! Some(numerator / denominator)
38+
//! }
39+
//! }
40+
//!
41+
//! // The return value of the function is an option
42+
//! let result = divide(2.0, 3.0);
3843
//!
3944
//! // Pattern match to retrieve the value
40-
//! match (cow_says, dog_says) {
41-
//! (Some(cow_words), Some(dog_words)) => {
42-
//! println!("Cow says {} and dog says {}!", cow_words, dog_words);
43-
//! }
44-
//! (Some(cow_words), None) => println!("Cow says {}", cow_words),
45-
//! (None, Some(dog_words)) => println!("Dog says {}", dog_words),
46-
//! (None, None) => println!("Cow and dog are suspiciously silent")
45+
//! match result {
46+
//! // The division was valid
47+
//! Some(x) => println!("Result: {}", x),
48+
//! // The division was invalid
49+
//! None => println!("Cannot divide by 0")
4750
//! }
4851
//! ```
4952
//!

branches/try2/src/libstd/option.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,23 @@
3030
//! of a value and take action, always accounting for the `None` case.
3131
//!
3232
//! ```
33-
//! # // FIXME This is not the greatest first example
34-
//! // cow_says contains the word "moo"
35-
//! let cow_says = Some("moo");
36-
//! // dog_says does not contain a value
37-
//! let dog_says: Option<&str> = None;
33+
//! fn divide(numerator: f64, denominator: f64) -> Option<f64> {
34+
//! if denominator == 0.0 {
35+
//! None
36+
//! } else {
37+
//! Some(numerator / denominator)
38+
//! }
39+
//! }
40+
//!
41+
//! // The return value of the function is an option
42+
//! let result = divide(2.0, 3.0);
3843
//!
3944
//! // Pattern match to retrieve the value
40-
//! match (cow_says, dog_says) {
41-
//! (Some(cow_words), Some(dog_words)) => {
42-
//! println!("Cow says {} and dog says {}!", cow_words, dog_words);
43-
//! }
44-
//! (Some(cow_words), None) => println!("Cow says {}", cow_words),
45-
//! (None, Some(dog_words)) => println!("Dog says {}", dog_words),
46-
//! (None, None) => println!("Cow and dog are suspiciously silent")
45+
//! match result {
46+
//! // The division was valid
47+
//! Some(x) => println!("Result: {}", x),
48+
//! // The division was invalid
49+
//! None => println!("Cannot divide by 0")
4750
//! }
4851
//! ```
4952
//!

0 commit comments

Comments
 (0)