Skip to content

Minor fixes for the macros chapter #1113

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

Merged
merged 3 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/macros/dry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ops::{Add, Mul, Sub};
macro_rules! assert_equal_len {
// The `tt` (token tree) designator is used for
// operators and tokens.
($a:ident, $b: ident, $func:ident, $op:tt) => (
($a:ident, $b:ident, $func:ident, $op:tt) => (
assert!($a.len() == $b.len(),
"{:?}: dimension mismatch: {:?} {:?} {:?}",
stringify!($func),
Expand Down Expand Up @@ -41,7 +41,7 @@ op!(sub_assign, Sub, -=, sub);
mod test {
use std::iter;
macro_rules! test {
($func: ident, $x:expr, $y:expr, $z:expr) => {
($func:ident, $x:expr, $y:expr, $z:expr) => {
#[test]
fn $func() {
for size in 0usize..10 {
Expand All @@ -57,7 +57,7 @@ mod test {
}
}

// Test `add_assign`, `mul_assign` and `sub_assign`
// Test `add_assign`, `mul_assign`, and `sub_assign`.
test!(add_assign, 1u32, 2u32, 3u32);
test!(mul_assign, 2u32, 3u32, 6u32);
test!(sub_assign, 3u32, 2u32, 1u32);
Expand Down
3 changes: 3 additions & 0 deletions src/macros/dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ Output:
This was a very simple example, but much more complex interfaces have been
developed, such as [`lazy_static`](https://crates.io/crates/lazy_static) or
[`clap`](https://crates.io/crates/clap).

Also, note the two pairs of braces in the macro. The outer ones are
part of the syntax of `macro_rules!`, in addition to `()` or `[]`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little confusing to me – which "macro" are you referring to here? what is the "outer one"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro that's defined, there's only one. It's almost a copy-paste from the first edition of the book:

The outer braces are part of the syntax of macro_rules!. In fact, you can use () or [] instead.
They simply delimit the right-hand side as a whole.

I didn't link to the book since it's the first edition and RBE only references the second one, which doesn't cover this bit.

Would you prefer something like this?

Also, note the two pairs of braces in the macro definition [or: in the calculate definition]. The outer braces are part of the syntax ...

If not, feel free to suggest a better version. I think it's important to explain this syntax since it's the first time it is used in this book.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frewsxcv @steveklabnik why is this not going forward?