From b922d1a40577e14df324ff36f69ad0f0e3857af7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez <guillaume1.gomez@gmail.com> Date: Thu, 24 Mar 2016 13:24:39 +0100 Subject: [PATCH] Improve some Option code example --- src/libcore/option.rs | 10 +++------- 1 file 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: