rust-lang/rust

API Docs: option

Closed this issue · 9 comments

In the as_mut and iter_mut examples, a match is used with a None => {} arm. if let would be more idiomatic.

In the documentation for unwrap_or (and maybe for related methods like ok_or and or), it would be nice to make a note that the arguments to a function are always fully evaluated, meaning that

fn foo(opt: Option<Bar>) -> Bar {
    let bar = opt.unwrap_or(return Bar::new());
    bar.baz()
}

will always return Bar::new() instead of opt.unwrap().baz(), even if opt is Some(_). This seems like a pitfall otherwise.

I am happy to mentor anyone who wants to tackle this issue.

@steveklabnik I'd like to help on this.

@irfanhudda awesome! Let me know if I can help you help us in any way :)

@steveklabnik Module level docs look fine here. I think the documentation of IntoIter, Iter and IterMut structs can be improved. Do we also need examples or anything else?

Oh, I just noticed I didn't add a checklist for this issue!

They do not need examples, but they should follow the standard iterator boilerplate: https://doc.rust-lang.org/stable/std/iter/struct.SkipWhile.html

An iterator that rejects elements while predicate is true.

This struct is created by the skip_while() method on Iterator. See its documentation for more.

I think this issue can be closed (as of #40999); the docs look pretty good now!