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 :)
The idea is pretty simple: Add a function called
someto booleans such that you can automatically convert to an option.The basic implementation wouldn't be much more than
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_elsestyle 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 :)