complete: macros

This commit is contained in:
seth 2021-06-25 15:04:52 +08:00
parent e5954bbb2b
commit e67dafa971
5 changed files with 15 additions and 16 deletions

View file

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

View file

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

View file

@ -2,9 +2,8 @@
// Make me compile, without taking the macro out of the module!
// Execute `rustlings hint macros3` for hints :)
// I AM NOT DONE
mod macros {
#[macro_export]
macro_rules! my_macro {
() => {
println!("Check out my macro!");

View file

@ -1,15 +1,13 @@
// macros4.rs
// Make me compile! Execute `rustlings hint macros4` for hints :)
// I AM NOT DONE
macro_rules! my_macro {
() => {
println!("Check out my macro!");
}
};
($val:expr) => {
println!("Look at this other macro: {}", $val);
}
};
}
fn main() {

View file

@ -5,7 +5,12 @@
// Write a macro that passes the quiz! No hints this time, you can do it!
// I AM NOT DONE
#[macro_export]
macro_rules! my_macro {
($val:expr) => {
format!("Hello {}", $val)
};
}
#[cfg(test)]
mod tests {