Skip to content

Commit b274729

Browse files
authored
Merge pull request #1205 from Rosto75/master
Update `macro_rules!` formatting.
2 parents 70f4354 + 3813838 commit b274729

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/macros.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Macros are created using the `macro_rules!` macro.
1414
// This is a simple macro named `say_hello`.
1515
macro_rules! say_hello {
1616
// `()` indicates that the macro takes no argument.
17-
() => (
17+
() => {
1818
// The macro will expand into the contents of this block.
1919
println!("Hello!");
20-
)
20+
};
2121
}
2222
2323
fn main() {

src/macros/designators.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ macro_rules! create_function {
88
// This macro takes an argument of designator `ident` and
99
// creates a function named `$func_name`.
1010
// The `ident` designator is used for variable/function names.
11-
($func_name:ident) => (
11+
($func_name:ident) => {
1212
fn $func_name() {
1313
// The `stringify!` macro converts an `ident` into a string.
1414
println!("You called {:?}()",
1515
stringify!($func_name));
1616
}
17-
)
17+
};
1818
}
1919
2020
// Create functions named `foo` and `bar` with the above macro.
@@ -25,12 +25,12 @@ macro_rules! print_result {
2525
// This macro takes an expression of type `expr` and prints
2626
// it as a string along with its result.
2727
// The `expr` designator is used for expressions.
28-
($expression:expr) => (
28+
($expression:expr) => {
2929
// `stringify!` will convert the expression *as it is* into a string.
3030
println!("{:?} = {:?}",
3131
stringify!($expression),
3232
$expression);
33-
)
33+
};
3434
}
3535
3636
fn main() {

src/macros/dry.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ use std::ops::{Add, Mul, Sub};
1010
macro_rules! assert_equal_len {
1111
// The `tt` (token tree) designator is used for
1212
// operators and tokens.
13-
($a:ident, $b:ident, $func:ident, $op:tt) => (
13+
($a:ident, $b:ident, $func:ident, $op:tt) => {
1414
assert!($a.len() == $b.len(),
1515
"{:?}: dimension mismatch: {:?} {:?} {:?}",
1616
stringify!($func),
1717
($a.len(),),
1818
stringify!($op),
1919
($b.len(),));
20-
)
20+
};
2121
}
2222
2323
macro_rules! op {
24-
($func:ident, $bound:ident, $op:tt, $method:ident) => (
24+
($func:ident, $bound:ident, $op:tt, $method:ident) => {
2525
fn $func<T: $bound<T, Output=T> + Copy>(xs: &mut Vec<T>, ys: &Vec<T>) {
2626
assert_equal_len!(xs, ys, $func, $op);
2727
@@ -30,7 +30,7 @@ macro_rules! op {
3030
// *x = x.$method(*y);
3131
}
3232
}
33-
)
33+
};
3434
}
3535
3636
// Implement `add_assign`, `mul_assign`, and `sub_assign` functions.
@@ -54,7 +54,7 @@ mod test {
5454
assert_eq!(x, z);
5555
}
5656
}
57-
}
57+
};
5858
}
5959
6060
// Test `add_assign`, `mul_assign`, and `sub_assign`.

src/macros/overload.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ In that regard, `macro_rules!` can work similarly to a match block:
99
macro_rules! test {
1010
// Arguments don't need to be separated by a comma.
1111
// Any template can be used!
12-
($left:expr; and $right:expr) => (
12+
($left:expr; and $right:expr) => {
1313
println!("{:?} and {:?} is {:?}",
1414
stringify!($left),
1515
stringify!($right),
1616
$left && $right)
17-
);
17+
};
1818
// ^ each arm must end with a semicolon.
19-
($left:expr; or $right:expr) => (
19+
($left:expr; or $right:expr) => {
2020
println!("{:?} or {:?} is {:?}",
2121
stringify!($left),
2222
stringify!($right),
2323
$left || $right)
24-
);
24+
};
2525
}
2626
2727
fn main() {

src/macros/repeat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro_rules! find_min {
2222
2323
fn main() {
2424
println!("{}", find_min!(1u32));
25-
println!("{}", find_min!(1u32 + 2 , 2u32));
25+
println!("{}", find_min!(1u32 + 2, 2u32));
2626
println!("{}", find_min!(5u32, 2u32 * 3, 4u32));
2727
}
2828
```

0 commit comments

Comments
 (0)