-
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::is_some_and and Result::is_{ok,err}_and #93050
Comments
What are the use-cases? And won't that largely be covered by if-let chains? if let Some(foo) = opt && foo > bar {
} |
Lots of functions on let deadline_passed = optional_deadline.is_some_with(|d| d < now);
let deadline_passed = matches!(optional_deadline, Some(d) if d < now);
let deadline_passed = if let Some(d) = optional_deadline && d < now { true } else { false }; |
I assume I think a code example with a bit more context that would benefit from this and wouldn't be replaced by if-let-chain in the future would be helpful.
Or maybe just |
|
This example about a
I've added |
There are 117 cases of |
The name |
After thinking about it a bit more, I like this name. It very clearly states that it first checks |
FWIW this was attempted in #75298. |
Rename is_{some,ok,err}_with to is_{some,ok,err}_and. This renames `is_{some,ok,err}_with` to `is_{some,ok,err}_and`. This was discussed on the [tracking issue](rust-lang#93050).
Needed for rust-lang/rust#93050
As someone who finds map_or both overly verbose for this (I need this version far more than the general case of map_or) and generally unpleasant (due to argument order not matching the name, although I 100% understand that decision even if I don't love it) I would be thrilled for this. I think the worry about overlap with if/let is valid but for filtering and other combinators this composes really well (having played with it some now) Also +1 to |
I often define similar functions in my code as an extension trait, and I would like to also see the |
Would love to see this stabilized. My usecase is checking if a submitted value matches the last value, if there was a last value: //Earlier, for example:
let last : Option<u64>;
let next : u64;
//In logic
if last.is_some_and(|v| v == next) {
return Err(());
} |
@AmitPr |
@m-ou-se: not if |
It seems like everybody is happy with the current names for these methods. I think it's time to consider stabilization. @rfcbot merge |
Team member @m-ou-se has proposed to merge 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. |
what is with Btw, I found this issue here by explicitly searching for |
|
Thx, does this mean we have to create a new issue for that method or is it somehow possible to attach it to this issue? I can also do the impl, just not sure how the process is. |
I think the function should take the |
Was there a resolution to the concern that the same behavior could be achieved with |
@SUPERCILEX |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@joshtriplett Fair enough, thanks! |
The final comment period, with a disposition to merge, 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. This will be merged soon. |
Is this just waiting for somebody to create a stabilization PR? I can probably do that if so. |
Yes. Feel free to go ahead. |
The description of this API in this tracking issue and in #110019 say that the closure takes |
We had a second FCP to change the closure to take |
I totally forgot about all that.. Well I guess I will live with it. The draft PR to show that it made |
for more information see issue #93050: rust-lang/rust#93050 Signed-off-by: Knut Borchers <knut.borchers@gmail.com>
Well, I don't know if these functions are really that essential. These checks can be made in several different ways. let data = Some("foo");
if data == Some("foo") {
//...
}
if data.is_some_and(|inner| inner == "foo") {
//...
}
if let Some(inner) = data && inner == "foo" {
//...
}
if matches!(data, Some(inner) if inner == "foo") {
//...
} The first might only be desirable in some cases, but the third one with |
In which version should we expect this feature? I thought it was going to be in 1.70.0, but apparently not. |
It is in 1.70.0 (see https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html) |
Feature gate:
#![feature(is_some_and)]
This is a tracking issue for
Option::is_some_and
,Result::is_ok_and
andResult::is_err_and
.Public API
Steps / History
Option::contains
andResult::contains
#62358 (comment)self
by value: Changeis_some_and
to take by value #98354Unresolved Questions
is_some_with
/is_ok_with
/is_err_with
is_some_and
/is_ok_and
/is_err_and
contains
/contains_err
and_is
/and_err_is
is
has
self
or&self
?The text was updated successfully, but these errors were encountered: