rust icon indicating copy to clipboard operation
rust copied to clipboard

Inaccuracy in the documentation for Option::unwrap_or_default

Open moenie99 opened this issue 1 year ago • 2 comments

Location

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

Summary

It appears that the example was wrongly adapted from Result::unwrap_or_default, however the example does not work here because parse will never return None, its returns a Result. It appears that ideally a more fitting example should be written.

moenie99 avatar Aug 02 '22 10:08 moenie99

The documentation seems alright? Yes, parse returns a Result -- The example is calling Result::ok to convert Result<T> to Option<T> and then using Option::unwrap_or_default.

gimbling-away avatar Aug 02 '22 10:08 gimbling-away

I think there could be for people like this (no offensive) type annotations.

ArtifyCZ avatar Aug 05 '22 22:08 ArtifyCZ

The example could be simplified indeed.

GuillaumeGomez avatar Sep 25 '22 09:09 GuillaumeGomez

@rustbot claim

gimbling-away avatar Sep 25 '22 10:09 gimbling-away