Skip to content
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

Consider adding simple pattern matching to the ensure macros #462

Open
shepmaster opened this issue Aug 13, 2024 · 1 comment
Open

Consider adding simple pattern matching to the ensure macros #462

shepmaster opened this issue Aug 13, 2024 · 1 comment
Labels
enhancement New feature or request feedback requested User feedback desired on a design decision

Comments

@shepmaster
Copy link
Owner

@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.

@shepmaster shepmaster added enhancement New feature or request feedback requested User feedback desired on a design decision labels Aug 13, 2024
@kelko
Copy link

kelko commented Sep 18, 2024

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feedback requested User feedback desired on a design decision
Projects
None yet
Development

No branches or pull requests

2 participants