]> git.lizzy.rs Git - rust.git/commitdiff
Improve some Option code example
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 24 Mar 2016 12:24:39 +0000 (13:24 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 24 Mar 2016 12:24:39 +0000 (13:24 +0100)
src/libcore/option.rs

index dd60e8797a948347c7bd2655d9cc0b81a02eddd4..beed2075d049427d2daa39365d0e1730ee901f58 100644 (file)
 //! 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: