Rollup merge of #32464 - GuillaumeGomez:patch-6, r=steveklabnik

Improve some Option code example

Part of #29366.

r? @steveklabnik
This commit is contained in:
Steve Klabnik 2016-03-24 10:37:24 -04:00
commit b2dfb7c0a2
1 changed files with 3 additions and 7 deletions

View File

@ -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: