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

Feature request: bigger enclosing block to use guards in bulk. #7

Closed
vi opened this issue Apr 19, 2019 · 4 comments
Closed

Feature request: bigger enclosing block to use guards in bulk. #7

vi opened this issue Apr 19, 2019 · 4 comments

Comments

@vi
Copy link

vi commented Apr 19, 2019

I want to write something like

guard_block! {
    let Some(b) = a else { return; }
    let Some(c) = b else { return; }
    foo(&c);
    let Some(d) = c else { return; }
}

instead of encasing everything in additional level of parenthesis:

guard!(let Some(b) = a else { return; });
guard!(let Some(c) = b else { return; });
foo(&c);
guard!(let Some(d) = c else { return; });

guard_block! { guard let Some(b) = a else { return; } } is fine too.

@vi
Copy link
Author

vi commented Apr 19, 2019

Also would it better be a proc macro instead of declarative?

The code looks tricky.

@durka
Copy link
Owner

durka commented Apr 22, 2019

This is ambiguous (one of the reasons the syntax was controversial in the RFC):

guard_block! {
    let x = if y { z } else { panic!() };
}

Is it a regular let or a guard-let? However, a block form with guard let statements seems doable.

I like tricky declarative macros!

@vi
Copy link
Author

vi commented Apr 22, 2019

Why is this crate unpopular (no reverse deps, few downloads), e.g. compared to if_chain?

Possible reasons:

  • Nobody needs guard lets; or
  • There is competitor crate that is popular; or
  • This crate works poorly; or
  • There is some typical workaround everybody use?

@durka
Copy link
Owner

durka commented Apr 22, 2019 via email

@durka durka closed this as completed Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants