-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
? patterns #2012
Comments
You can do this using |
Oh you actually want an |
@burdges What do you mean? |
I see, |
Yeah, exactly, I think it would make sense just as a general pattern too: let foo? = bar(); would be allowed to be equivalent to: let foo = bar()?; |
That seems a bit confusing. It makes it seem like the for line in stdin.lock().lines()? { // Where each new item has the question mark operator work on it
// do something with line
} |
Doing |
Right. I wasn't clear, I should have said an iterator after in with a question mark would do the unwrapping of the value returned while iterated through. |
The only syntax I could see being added, that's not in the pattern, is |
EDIT: Actually, that isn't an absolutely horrible idea. Maybe we could have like |
I think it should extend pattern matching in general, not be special syntax for Ideas around coroutines, futures, etc. could perhaps be used to generalize
I despise that idea though because if As an aside, I'd write the original code to avoid introducing another name. I might insert context not allowed by
I'm dubious about incorporating
|
Previous discussion: https://internals.rust-lang.org/t/pre-rfc-allow-in-patterns/4772 |
I'm still biased against the addition of the |
I've wanted something like this for a while, and I'd like to see some reasonable syntax for it. |
Triage ping: Any updates on this? |
That for loop example is compelling, but having this in the pattern scares me. It reminds me too much of let x = &y;
let ref x = y; So I wouldn't want to end up with debates about which of the following to use: let x = y?:
let x? = y; Not that I have a good solution to propose... |
|
I've written a lot of code like this for libraries that use Iterators where the Item is a Result:
I think it would be awesome if we could just relocate the
?
to the pattern, like this:The text was updated successfully, but these errors were encountered: