Going through rustlings for the first time

ex(21): macros

Changed files
+54 -17
exercises
solutions
+6 -2
.rustlings-state.txt
··· 1 1 DON'T EDIT THIS FILE! 2 2 3 - macros1 3 + clippy1 4 4 5 5 intro1 6 6 intro2 ··· 83 83 cow1 84 84 threads1 85 85 threads2 86 - threads3 86 + threads3 87 + macros1 88 + macros2 89 + macros3 90 + macros4
+1 -1
exercises/21_macros/macros1.rs
··· 6 6 7 7 fn main() { 8 8 // TODO: Fix the macro call. 9 - my_macro(); 9 + my_macro!(); 10 10 }
+4 -4
exercises/21_macros/macros2.rs
··· 1 - fn main() { 2 - my_macro!(); 3 - } 4 - 5 1 // TODO: Fix the compiler error by moving the whole definition of this macro. 6 2 macro_rules! my_macro { 7 3 () => { 8 4 println!("Check out my macro!"); 9 5 }; 10 6 } 7 + 8 + fn main() { 9 + my_macro!(); 10 + }
+1
exercises/21_macros/macros3.rs
··· 1 1 // TODO: Fix the compiler error without taking the macro definition out of this 2 2 // module. 3 + #[macro_use] 3 4 mod macros { 4 5 macro_rules! my_macro { 5 6 () => {
+2 -2
exercises/21_macros/macros4.rs
··· 3 3 macro_rules! my_macro { 4 4 () => { 5 5 println!("Check out my macro!"); 6 - } 6 + }; 7 7 ($val:expr) => { 8 8 println!("Look at this other macro: {}", $val); 9 - } 9 + }; 10 10 } 11 11 12 12 fn main() {
+8 -2
solutions/21_macros/macros1.rs
··· 1 + macro_rules! my_macro { 2 + () => { 3 + println!("Check out my macro!"); 4 + }; 5 + } 6 + 1 7 fn main() { 2 - // DON'T EDIT THIS SOLUTION FILE! 3 - // It will be automatically filled after you finish the exercise. 8 + my_macro!(); 9 + // ^ 4 10 }
+8 -2
solutions/21_macros/macros2.rs
··· 1 + // Moved the macro definition to be before its call. 2 + macro_rules! my_macro { 3 + () => { 4 + println!("Check out my macro!"); 5 + }; 6 + } 7 + 1 8 fn main() { 2 - // DON'T EDIT THIS SOLUTION FILE! 3 - // It will be automatically filled after you finish the exercise. 9 + my_macro!(); 4 10 }
+11 -2
solutions/21_macros/macros3.rs
··· 1 + // Added the attribute `macro_use` attribute. 2 + #[macro_use] 3 + mod macros { 4 + macro_rules! my_macro { 5 + () => { 6 + println!("Check out my macro!"); 7 + }; 8 + } 9 + } 10 + 1 11 fn main() { 2 - // DON'T EDIT THIS SOLUTION FILE! 3 - // It will be automatically filled after you finish the exercise. 12 + my_macro!(); 4 13 }
+13 -2
solutions/21_macros/macros4.rs
··· 1 + // Added semicolons to separate the macro arms. 2 + #[rustfmt::skip] 3 + macro_rules! my_macro { 4 + () => { 5 + println!("Check out my macro!"); 6 + }; 7 + ($val:expr) => { 8 + println!("Look at this other macro: {}", $val); 9 + }; 10 + } 11 + 1 12 fn main() { 2 - // DON'T EDIT THIS SOLUTION FILE! 3 - // It will be automatically filled after you finish the exercise. 13 + my_macro!(); 14 + my_macro!(7777); 4 15 }