Add macros solutions

This commit is contained in:
David Bailey 2021-01-17 00:19:45 +00:00
parent 0202ba2869
commit 39dcd550a7
4 changed files with 8 additions and 15 deletions

View file

@ -1,8 +1,6 @@
// macros1.rs // macros1.rs
// Make me compile! Execute `rustlings hint macros1` for hints :) // Make me compile! Execute `rustlings hint macros1` for hints :)
// I AM NOT DONE
macro_rules! my_macro { macro_rules! my_macro {
() => { () => {
println!("Check out my macro!"); println!("Check out my macro!");
@ -10,5 +8,5 @@ macro_rules! my_macro {
} }
fn main() { fn main() {
my_macro(); my_macro!();
} }

View file

@ -1,14 +1,12 @@
// macros2.rs // macros2.rs
// Make me compile! Execute `rustlings hint macros2` for hints :) // Make me compile! Execute `rustlings hint macros2` for hints :)
// I AM NOT DONE
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,8 +2,7 @@
// Make me compile, without taking the macro out of the module! // Make me compile, without taking the macro out of the module!
// Execute `rustlings hint macros3` for hints :) // Execute `rustlings hint macros3` for hints :)
// I AM NOT DONE #[macro_use]
mod macros { mod macros {
macro_rules! my_macro { macro_rules! my_macro {
() => { () => {

View file

@ -1,15 +1,13 @@
// macros4.rs // macros4.rs
// Make me compile! Execute `rustlings hint macros4` for hints :) // Make me compile! Execute `rustlings hint macros4` for hints :)
// I AM NOT DONE
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);
} };
} }
fn main() { fn main() {