mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #25920 - tshepang:option-map-example, r=Gankro
This commit is contained in:
commit
9c77784668
@ -409,9 +409,11 @@ impl<T> Option<T> {
|
||||
/// Convert an `Option<String>` into an `Option<usize>`, consuming the original:
|
||||
///
|
||||
/// ```
|
||||
/// let num_as_str: Option<String> = Some("10".to_string());
|
||||
/// // `Option::map` takes self *by value*, consuming `num_as_str`
|
||||
/// let num_as_int: Option<usize> = num_as_str.map(|n| n.len());
|
||||
/// let maybe_some_string = Some(String::from("Hello, World!"));
|
||||
/// // `Option::map` takes self *by value*, consuming `maybe_some_string`
|
||||
/// let maybe_some_len = maybe_some_string.map(|s| s.len());
|
||||
///
|
||||
/// assert_eq!(maybe_some_len, Some(13));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
Loading…
Reference in New Issue
Block a user