Improve some Option code example
This commit is contained in:
parent
43843d06ea
commit
b922d1a405
1 changed files with 3 additions and 7 deletions
|
@ -93,16 +93,12 @@
|
||||||
//! let msg = Some("howdy");
|
//! let msg = Some("howdy");
|
||||||
//!
|
//!
|
||||||
//! // Take a reference to the contained string
|
//! // Take a reference to the contained string
|
||||||
//! match msg {
|
//! if let Some(ref m) = msg {
|
||||||
//! Some(ref m) => println!("{}", *m),
|
//! println!("{}", *m);
|
||||||
//! None => (),
|
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! // Remove the contained string, destroying the Option
|
//! // Remove the contained string, destroying the Option
|
||||||
//! let unwrapped_msg = match msg {
|
//! let unwrapped_msg = msg.unwrap_or("default message");
|
||||||
//! Some(m) => m,
|
|
||||||
//! None => "default message",
|
|
||||||
//! };
|
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Initialize a result to `None` before a loop:
|
//! Initialize a result to `None` before a loop:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue