Skip to content

Suggestion: assert pattern macro. #24429

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

Closed
norcalli opened this issue Apr 14, 2015 · 2 comments
Closed

Suggestion: assert pattern macro. #24429

norcalli opened this issue Apr 14, 2015 · 2 comments

Comments

@norcalli
Copy link
Contributor

macro_rules! assert_pattern {
    ($a:expr => $b:pat) => {
        assert!(match $a { $b => true, _ => false });
    }
}

Something like this would be useful for checking a pattern instead of deriving Eq,PartialEq for an enum.

@alexcrichton
Copy link
Member

There's actually a crates on crates.io that does this already! https://crates.io/crates/matches

Right now we're also tracking new feature requests in the RFC repo, so if you feel that it still needs to be included in the stdlib by default, feel free to open an issue!

@alexcrichton
Copy link
Member

Er, looks like there's already an issue!

rust-lang/rfcs#264

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