Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve docs for collecting into Options #56342

Merged
merged 1 commit into from
Dec 24, 2018

Conversation

killercup
Copy link
Member

Changes the original example to use more idiomatic formatting as well
as .checked_add. Also adds a second example to show a case where the
.collect returns None.

@rust-highfive
Copy link
Collaborator

r? @bluss

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 29, 2018
///
/// let res: Option<Vec<u16>> = items
/// .iter()
/// .map(|x| x.checked_add(1))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is an obvious function or should be explain more (or use the explicit impl of checked adding as it did previously)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems fine as it is, maybe it comes best together if we mention that checked_add/_sub returns None on overflow, on this example or the next?

Changes the original example to use more idiomatic formatting as well
as `.checked_add`. Also adds a second example to show a case where the
`.collect` returns `None`.
@killercup
Copy link
Member Author

Sorry, totally missed that comment, @bluss! Added this:

We use the checked variant of add that returns None when the calculation would result in an overflow.

@bluss
Copy link
Member

bluss commented Dec 23, 2018

@bors r+ rollup

Thanks!

@bors
Copy link
Contributor

bors commented Dec 23, 2018

📌 Commit 2c0f011 has been approved by bluss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 23, 2018
Centril added a commit to Centril/rust that referenced this pull request Dec 23, 2018
… r=bluss

Improve docs for collecting into `Option`s

Changes the original example to use more idiomatic formatting as well
as `.checked_add`. Also adds a second example to show a case where the
`.collect` returns `None`.
bors added a commit that referenced this pull request Dec 24, 2018
Rollup of 14 pull requests

Successful merges:

 - #56188 (enum type instead of variant suggestion unification )
 - #56342 (Improve docs for collecting into `Option`s)
 - #56916 (Fix mutable references in `static mut`)
 - #56917 (Simplify MIR generation for logical operations)
 - #56939 (Pin stabilization)
 - #56953 (Mark tuple structs as live if their constructors are used)
 - #56964 (Remove `TokenStream::JointTree`.)
 - #56966 (Correct strings for raw pointer deref and array access suggestions)
 - #57020 (Point to cause of `fn` expected return type)
 - #57032 (fix deprecation warnings in liballoc benches)
 - #57053 (Fix alignment for array indexing)
 - #57062 (Fix a comment)
 - #57067 (Stabilize min_const_unsafe_fn in 1.33)
 - #57078 (Ignore two tests on s390x)

Failed merges:

r? @ghost
@bors bors merged commit 2c0f011 into rust-lang:master Dec 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants