snafu
snafu copied to clipboard
Consider adding simple pattern matching to the ensure macros
@Kyuuhachi says:
I like to include that clause when I make a project-local ensure macro
"That clause" means something like this:
ensure!(let Some(x) = y, SomeSnafu);
This could expand into something like
let Some(x) = y else { return SomeSnafu.fail() };
To consider is if there's a way to do it with something besides let-else, which only stabilized in 1.65.
To consider is if there's a way to do it with something besides let-else, which only stabilized in 1.65.
(Just passing through, leaving my 2 cents)
Isn't let Some(x) = y else { return SomeSnafu.fail() }; just sugar for
let x = match y {
Some(x) => x,
_ => return SomeSnafu.fail(),
}
But that would probably require a more sophisticated macro definition, as it would need to deconstruct the "that clause"