Skip to content

Commit

Permalink
Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcm
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Yuki Okushi authored Jan 14, 2023
2 parents a11eb4f + 123e203 commit 6702f20
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,14 @@ impl<T> Option<T> {
///
/// # Examples
///
/// Converts an <code>Option<[String]></code> into an <code>Option<[usize]></code>, preserving
/// the original. The [`map`] method takes the `self` argument by value, consuming the original,
/// so this technique uses `as_ref` to first take an `Option` to a reference
/// to the value inside the original.
/// Calculates the length of an <code>Option<[String]></code> as an <code>Option<[usize]></code>
/// without moving the [`String`]. The [`map`] method takes the `self` argument by value,
/// consuming the original, so this technique uses `as_ref` to first take an `Option` to a
/// reference to the value inside the original.
///
/// [`map`]: Option::map
/// [String]: ../../std/string/struct.String.html "String"
/// [`String`]: ../../std/string/struct.String.html "String"
///
/// ```
/// let text: Option<String> = Some("Hello, world!".to_string());
Expand Down Expand Up @@ -946,8 +947,8 @@ impl<T> Option<T> {
///
/// # Examples
///
/// Converts an <code>Option<[String]></code> into an <code>Option<[usize]></code>, consuming
/// the original:
/// Calculates the length of an <code>Option<[String]></code> as an
/// <code>Option<[usize]></code>, consuming the original:
///
/// [String]: ../../std/string/struct.String.html "String"
/// ```
Expand Down

0 comments on commit 6702f20

Please sign in to comment.