complete: macros
This commit is contained in:
parent
e5954bbb2b
commit
e67dafa971
exercises
|
@ -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!();
|
||||
}
|
||||
|
|
|
@ -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!();
|
||||
}
|
|
@ -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!");
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue