complete: macros
This commit is contained in:
parent
e5954bbb2b
commit
e67dafa971
exercises
|
@ -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!();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
// 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!();
|
||||||
|
}
|
|
@ -2,9 +2,8 @@
|
||||||
// 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
|
|
||||||
|
|
||||||
mod macros {
|
mod macros {
|
||||||
|
#[macro_export]
|
||||||
macro_rules! my_macro {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
println!("Check out my macro!");
|
println!("Check out my macro!");
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -5,7 +5,12 @@
|
||||||
|
|
||||||
// Write a macro that passes the quiz! No hints this time, you can do it!
|
// 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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
Loading…
Reference in a new issue