-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.
Description
The idea is pretty simple: Add a function called some
to booleans such that you can automatically convert to an option.
The basic implementation wouldn't be much more than
fn some<T>(self, data: T) -> Option<T> {
if self {
Some(data)
} else {
None
}
}
The purpose of this would be to be able to write something like regex.is_match(string).some(token)
without having to explicitly set up an if-statement.
Maybe also add in an *_or_else
style function that takes a closure as an input, such that the true case is only ever allocated if it succeeds: regex.is_match(string).and_some(|| build_token())
.
Yes/No/Maybe?
I'd like to hear your opinions :)
mark-i-m, petrochenkov, CryZe, zesterer, 3442853561 and 21 moreH2CO3stepancheg
Metadata
Metadata
Assignees
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.