Skip to content

Commit 6702f20

Browse files
author
Yuki Okushi
authored
Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcm
reword Option::as_ref and Option::map examples The description for the examples of `Option::as_ref` and `Option::map` imply that the example is only doing type conversion, when it is actually finding the length of a string. Changes the wording to imply that some operation is being run on the value contained in the `Option` closes #104476
2 parents a11eb4f + 123e203 commit 6702f20

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

library/core/src/option.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,14 @@ impl<T> Option<T> {
652652
///
653653
/// # Examples
654654
///
655-
/// Converts an <code>Option<[String]></code> into an <code>Option<[usize]></code>, preserving
656-
/// the original. The [`map`] method takes the `self` argument by value, consuming the original,
657-
/// so this technique uses `as_ref` to first take an `Option` to a reference
658-
/// to the value inside the original.
655+
/// Calculates the length of an <code>Option<[String]></code> as an <code>Option<[usize]></code>
656+
/// without moving the [`String`]. The [`map`] method takes the `self` argument by value,
657+
/// consuming the original, so this technique uses `as_ref` to first take an `Option` to a
658+
/// reference to the value inside the original.
659659
///
660660
/// [`map`]: Option::map
661661
/// [String]: ../../std/string/struct.String.html "String"
662+
/// [`String`]: ../../std/string/struct.String.html "String"
662663
///
663664
/// ```
664665
/// let text: Option<String> = Some("Hello, world!".to_string());
@@ -946,8 +947,8 @@ impl<T> Option<T> {
946947
///
947948
/// # Examples
948949
///
949-
/// Converts an <code>Option<[String]></code> into an <code>Option<[usize]></code>, consuming
950-
/// the original:
950+
/// Calculates the length of an <code>Option<[String]></code> as an
951+
/// <code>Option<[usize]></code>, consuming the original:
951952
///
952953
/// [String]: ../../std/string/struct.String.html "String"
953954
/// ```

0 commit comments

Comments
 (0)