Skip to content

Update macro rules to account for 1.32.0 changes#32

Open
TonySamuels wants to merge 1 commit intoDanielKeep:masterfrom
TonySamuels:patch-1
Open

Update macro rules to account for 1.32.0 changes#32
TonySamuels wants to merge 1 commit intoDanielKeep:masterfrom
TonySamuels:patch-1

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.

2 participants