Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ameknite opened this issue Feb 3, 2023 · 1 comment · Fixed by #107632
Closed

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

ameknite opened this issue Feb 3, 2023 · 1 comment · Fixed by #107632
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@ameknite
Copy link
Contributor

ameknite commented Feb 3, 2023

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);
@ameknite ameknite added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Feb 3, 2023
@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 3, 2023
@jyn514
Copy link
Member

jyn514 commented Feb 3, 2023

@ameknite are you interested in making a PR adding this documentation? :) there are instructions at https://rustc-dev-guide.rust-lang.org/

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants