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

Implement Option::contains and Result::contains #62356

Merged
merged 1 commit into from Jul 8, 2019

Conversation

Projects
None yet
8 participants
@soc
Copy link
Contributor

commented Jul 3, 2019

This increases consistency with other common data structures.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Jul 3, 2019

r? @alexcrichton

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

Show resolved Hide resolved src/libcore/option.rs Outdated
Show resolved Hide resolved src/libcore/result.rs Outdated
Show resolved Hide resolved src/libcore/result.rs
Show resolved Hide resolved src/libcore/option.rs
Show resolved Hide resolved src/libcore/result.rs
@Centril

This comment has been minimized.

Copy link
Member

commented Jul 4, 2019

I filed a tracking issue for you in #62358.

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 4, 2019

This seems like quite a useful addition to me!

I know I've wanted this a bunch of times and opt.filter(|x| == y).is_some() doesn't read as well / is not as direct.

@cramertj

This comment has been minimized.

Copy link
Member

commented Jul 4, 2019

opt.filter(|x| == y).is_some() doesn't read as well / is not as direct.

FWIW, I've always done opt.map(|x| x == y).unwrap_or(false)

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 4, 2019

@rust-highfive rust-highfive assigned Centril and unassigned alexcrichton Jul 4, 2019

@soc

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2019

@Centril Thanks! I'll squash the commits as soon as you are happy with the code.

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 4, 2019

@soc It looks good to me so go ahead and squash now :)

As for fn contains_err / fn err_contains that can be deferred to some future PR.

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 4, 2019

@soc Can you please apply @Mark-Simulacrum's suggestion in #62358 (comment)?

@soc

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2019

It looks good to me so go ahead and squash now :)

Will do!

As for fn contains_err / fn err_contains that can be deferred to some future PR.

Agreed.

I think there are also a few additional combinators that could be considered (like filter_...). Might make sense to get the bigger picture on operations that are not used all the time, but are painful to work around their absence.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

commented Jul 4, 2019

I usually use my_option == Some(value) for this and it works most of the time.

For the cases where it doesn't work it would be much more useful to implement heterogeneous comparisons T: PartialEq<U> => Option<T>: PartialEq<Option<U>>, but that's blocked on type parameter fallback in type inference.

@soc soc force-pushed the soc:topic/contains branch from 1846868 to cf2fe83 Jul 4, 2019

Show resolved Hide resolved src/libcore/result.rs Outdated
@soc

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2019

@Centril Added contains_err and squashed. Good to go?

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

@soc Seems you have some test failures (see https://dev.azure.com/rust-lang/rust/_build/results?buildId=2412). While fixing those, can you also address @fbstj's comment? -- Also, can you split contains_err into a separate feature gate while at it?

@soc

This comment has been minimized.

Copy link
Contributor Author

commented Jul 5, 2019

@Centril Will do, thanks!

@soc soc force-pushed the soc:topic/contains branch from cf2fe83 to febd984 Jul 6, 2019

@soc

This comment has been minimized.

Copy link
Contributor Author

commented Jul 6, 2019

@Centril Done!

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 6, 2019

Thanks! r=me rollup when green

@soc soc force-pushed the soc:topic/contains branch 2 times, most recently from 084bfd2 to 4e37908 Jul 7, 2019

Implement Option::contains, Result::contains and Result::contains_err
This increases consistency with other common data structures.

@soc soc force-pushed the soc:topic/contains branch from 4e37908 to 6f76da4 Jul 7, 2019

@soc

This comment has been minimized.

Copy link
Contributor Author

commented Jul 7, 2019

@Centril Tests are green!

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 7, 2019

Thanks! @bors r+ rollup

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 7, 2019

📌 Commit 6f76da4 has been approved by Centril

Centril added a commit to Centril/rust that referenced this pull request Jul 8, 2019

Rollup merge of rust-lang#62356 - soc:topic/contains, r=Centril
Implement Option::contains and Result::contains

This increases consistency with other common data structures.

@Centril Centril referenced this pull request Jul 8, 2019

Closed

Rollup of 4 pull requests #62484

Centril added a commit to Centril/rust that referenced this pull request Jul 8, 2019

Rollup merge of rust-lang#62356 - soc:topic/contains, r=Centril
Implement Option::contains and Result::contains

This increases consistency with other common data structures.

@Centril Centril referenced this pull request Jul 8, 2019

Merged

Rollup of 5 pull requests #62485

bors added a commit that referenced this pull request Jul 8, 2019

Auto merge of #62485 - Centril:rollup-gg3it1u, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #62356 (Implement Option::contains and Result::contains)
 - #62462 (Document `while` keyword)
 - #62472 (Normalize use of backticks in compiler messages p2)
 - #62477 (Re-add bootstrap attribute to libunwind for llvm-libunwind feature)
 - #62478 (normalize use of backticks for compiler messages in librustc_codegen)

Failed merges:

r? @ghost

@bors bors merged commit 6f76da4 into rust-lang:master Jul 8, 2019

3 checks passed

pr Build #20190707.43 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details

@soc soc deleted the soc:topic/contains branch Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.