-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for Option::contains
and Result::contains
#62358
Comments
Should we update the signatures to |
@Mark-Simulacrum That seems like a good idea -- type inference should be driven by |
Looks like |
@Mark-Simulacrum I didn't do that because I checked the collections first, and they were all invariant. Shall I change this for |
We usually can't change preexisting APIs due to inference breakage, but since this is new, we should be able to be general. |
Are these functionally equivalent? pub fn contains(&self, x: &T) -> bool where T: PartialEq {
match self {
Some(y) => y == x,
None => false,
}
} pub fn contains(&self, x: &T) -> bool where T: PartialEq {
self.as_ref() == Some(x)
} |
@frewsxcv Not quite, due to the requested variance changes. |
What does that mean @soc? |
@czipperz The implementation is:
The argument doesn't have to be of the same type as the value inside option/result, only that it knows how to compare itself to it. I. e. the operation is not invariant on the contained type, it allows an arbitrary type. |
So there's no implementation of |
There is indeed not, see #20063. |
This matches the new `contains` method of Option: rust-lang/rust#62358
These methods are way too high up in the docs on both the |
What is the status on this? I would love to use these in stable. |
Assume you have a function |
how about |
But in the end, Rust is a typed language, so we should not be scared that much about confusion, because the types tell us which |
Naming bikeshed. Sorry if this is the wrong place. How about the names |
Team member @Amanieu has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
My anecdotal experience with Scala, which has an |
@BrianLondon To avoid any disappointment, please refer to
to learn about the community's preferences on this topic. Thanks! |
Thanks @soc, is there a document you're quoting? If so can you link to the original please? I'd like to read the rest of it. I think you're making some incorrect assumptions about my motivations. To be clear I am not suggesting a carbon copy of Scala, or even proposing to bring any particular Scala idiom into Rust. I am categorically not, for example, saying |
@BrianLondon soc does not speak for the community, and as a member of libs-api, I am generally happy to hear about experiences from other programming languages. (Although I do always, regardless of language, cast a skeptical eye because it can be tricky to analogize different environments. But I think your experience is relevant here.) |
@BrianLondon, @soc is just quoting earlier comments in this thread where they got into a squabble with another individual, so no need to worry about that. Generally the community is welcoming to different perspectives. |
I personally think that |
As the moderator who handled the referred situation, I want to confirm that Brian's original comment from yesterday was not of the same problems. What was done well was that Brian noted that their experience was anecdotal, not treating their views as authoritative, and they also softened their contribution by acknowledging what they weren't aware of. This makes a world of difference in how one brings outside experience to Rust. |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err` This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`. The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in rust-lang#93051 obviates the need for these methods (non-stabilization tracked in rust-lang#62358). An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library: ![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
@Centril methods have been removed, this issue can be closed now. |
Per rust-lang/rust#62358, this feature has been removed. To prepare for a future nightly toolchain bump, this replaces all the places we're using Option::contains with `iter().any(...)`. Change-Id: Idd507bdc9b35415061e3b7b8b37cc98bbb980c77 Reviewed-on: https://gerrit.readyset.name/c/readyset/+/4612 Tested-by: Buildkite CI Reviewed-by: Dan Wilbanks <[email protected]>
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err` This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`. The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in rust-lang/rust#93051 obviates the need for these methods (non-stabilization tracked in rust-lang/rust#62358). An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library: ![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
i tried to remove |
@univerz As per above commit one could also replace by |
@univerz Perhaps option-ext can be of use to you! |
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err` This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`. The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in rust-lang/rust#93051 obviates the need for these methods (non-stabilization tracked in rust-lang/rust#62358). An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library: ![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err` This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`. The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in rust-lang/rust#93051 obviates the need for these methods (non-stabilization tracked in rust-lang/rust#62358). An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library: ![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err` This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`. The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in rust-lang/rust#93051 obviates the need for these methods (non-stabilization tracked in rust-lang/rust#62358). An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library: ![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
This is a tracking issue for
Option::contains
andResult::contains
.The implementations are as follows:
The text was updated successfully, but these errors were encountered: