Skip to content

Conversation

soc
Copy link

@soc soc commented Jul 3, 2019

This increases consistency with other common data structures.

@rust-highfive
Copy link
Contributor

r? @alexcrichton

(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 Jul 3, 2019
@Centril
Copy link
Contributor

Centril commented Jul 4, 2019

I filed a tracking issue for you in #62358.

@Centril
Copy link
Contributor

Centril 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
Copy link
Member

cramertj 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
Copy link
Contributor

Centril commented Jul 4, 2019

r? @Centril

@rust-highfive rust-highfive assigned Centril and unassigned alexcrichton Jul 4, 2019
@soc
Copy link
Author

soc commented Jul 4, 2019

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

@Centril
Copy link
Contributor

Centril 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
Copy link
Contributor

Centril commented Jul 4, 2019

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

@soc
Copy link
Author

soc 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
Copy link
Contributor

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
Copy link
Author

soc commented Jul 4, 2019

@Centril Added contains_err and squashed. Good to go?

@Centril
Copy link
Contributor

Centril 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?

@Centril Centril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 5, 2019
@soc
Copy link
Author

soc commented Jul 5, 2019

@Centril Will do, thanks!

@soc
Copy link
Author

soc commented Jul 6, 2019

@Centril Done!

@Centril
Copy link
Contributor

Centril commented Jul 6, 2019

Thanks! r=me rollup when green

This increases consistency with other common data structures.
@soc
Copy link
Author

soc commented Jul 7, 2019

@Centril Tests are green!

@Centril
Copy link
Contributor

Centril commented Jul 7, 2019

Thanks! @bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 7, 2019

📌 Commit 6f76da4 has been approved by Centril

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 7, 2019
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 7, 2019
Centril added a commit to Centril/rust that referenced this pull request Jul 8, 2019
Implement Option::contains and Result::contains

This increases consistency with other common data structures.
Centril added a commit to Centril/rust that referenced this pull request Jul 8, 2019
Implement Option::contains and Result::contains

This increases consistency with other common data structures.
bors added a commit that referenced this pull request Jul 8, 2019
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
@soc soc deleted the topic/contains branch July 8, 2019 08:07
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.

8 participants