Skip to content

Make it clear that .map() returns None if None. #107622

Closed
@ameknite

Description

@ameknite

Location

https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.map

Summary

I think it would be nice if the .map() documentation made it clear that when None is consumed by .map() returns None, to make it consistent with .map_or() and .map_or_else() because right now it just says:

Maps an Option<T> to Option<U> by applying a function to a contained value.

Example in .map.or()

"Returns the provided default result (if none), or applies a function to the contained value (if any)."

https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.map_or.

and maybe add a little example like:

let x: Option<&str> = None;
assert_eq!(x.map(|s| s.len()), None);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions