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

Update macro rules to account for 1.32.0 changes #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TonySamuels
Copy link

https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html

Macro improvements
A few improvements to macros have landed in Rust 1.32.0. First, a new literal matcher was added:

macro_rules! m {
    ($lt:literal) => {};
}

fn main() {
    m!("some string literal");
}

literal matches against literals of any type; string literals, numeric literals, char literals.

In the 2018 edition, macro_rules macros can also use ?, like this:

macro_rules! bar {
    ($(a)?) => {}
}

The ? will match zero or one repetitions of the pattern, similar to the already-existing * for "zero or more" and + for "one or more."

https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html

Macro improvements
A few improvements to macros have landed in Rust 1.32.0. First, a new `literal` matcher was added:

```rust
macro_rules! m {
    ($lt:literal) => {};
}

fn main() {
    m!("some string literal");
}
```
`literal` matches against literals of any type; string literals, numeric literals, `char` literals.

In the 2018 edition, `macro_rules` macros can also use `?`, like this:

```rust
macro_rules! bar {
    ($(a)?) => {}
}
```
The `?` will match zero or one repetitions of the pattern, similar to the already-existing `*` for "zero or more" and `+` for "one or more."
@TonySamuels
Copy link
Author

This resolves #27.

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

Successfully merging this pull request may close these issues.

None yet

2 participants