diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-03-24 13:24:39 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-03-24 13:24:39 +0100 |
| commit | b922d1a40577e14df324ff36f69ad0f0e3857af7 (patch) | |
| tree | 3e3adc0a17fa7a02d67e176a0d158d67e876eb3f /src/libcore | |
| parent | 43843d06ea9598722b3af9019e8d0059c052382d (diff) | |
Improve some Option code example
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/option.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index dd60e8797a9..beed2075d04 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -93,16 +93,12 @@ //! let msg = Some("howdy"); //! //! // Take a reference to the contained string -//! match msg { -//! Some(ref m) => println!("{}", *m), -//! None => (), +//! if let Some(ref m) = msg { +//! println!("{}", *m); //! } //! //! // Remove the contained string, destroying the Option -//! let unwrapped_msg = match msg { -//! Some(m) => m, -//! None => "default message", -//! }; +//! let unwrapped_msg = msg.unwrap_or("default message"); //! ``` //! //! Initialize a result to `None` before a loop: |
