Skip to content

Commit 8221715

Browse files
committed
doc: improve Option::map example
1 parent 78c4d53 commit 8221715

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/libcore/option.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,11 @@ impl<T> Option<T> {
409409
/// Convert an `Option<String>` into an `Option<usize>`, consuming the original:
410410
///
411411
/// ```
412-
/// let num_as_str: Option<String> = Some("10".to_string());
413-
/// // `Option::map` takes self *by value*, consuming `num_as_str`
414-
/// let num_as_int: Option<usize> = num_as_str.map(|n| n.len());
412+
/// let maybe_some_string = Some(String::from("Hello, World!"));
413+
/// // `Option::map` takes self *by value*, consuming `maybe_some_string`
414+
/// let maybe_some_len = maybe_some_string.map(|s| s.len());
415+
///
416+
/// assert_eq!(maybe_some_len, Some(13));
415417
/// ```
416418
#[inline]
417419
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)