Complete macros section

This commit is contained in:
Paul Czeresko 2019-07-22 11:32:04 -04:00
parent b3b9da0fbf
commit d6a79f2399
4 changed files with 8 additions and 6 deletions

View file

@ -8,7 +8,7 @@ macro_rules! my_macro {
} }
fn main() { fn main() {
my_macro(); my_macro!();
} }

View file

@ -1,16 +1,17 @@
// macros2.rs // macros2.rs
// Make me compile! Scroll down for hints :) // Make me compile! Scroll down for hints :)
fn main() {
my_macro!();
}
macro_rules! my_macro { macro_rules! my_macro {
() => { () => {
println!("Check out my macro!"); println!("Check out my macro!");
}; };
} }
fn main() {
my_macro!();
}

View file

@ -2,6 +2,7 @@
// Make me compile, without taking the macro out of the module! Scroll down for hints :) // Make me compile, without taking the macro out of the module! Scroll down for hints :)
mod macros { mod macros {
#[macro_export]
macro_rules! my_macro { macro_rules! my_macro {
() => { () => {
println!("Check out my macro!"); println!("Check out my macro!");

View file

@ -4,7 +4,7 @@
macro_rules! my_macro { macro_rules! my_macro {
() => { () => {
println!("Check out my macro!"); println!("Check out my macro!");
} };
($val:expr) => { ($val:expr) => {
println!("Look at this other macro: {}", $val); println!("Look at this other macro: {}", $val);
} }