macros and stuff
This commit is contained in:
parent
9bdf1995ef
commit
aeaa001b38
exercises
|
@ -8,7 +8,7 @@ macro_rules! my_macro {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
my_macro();
|
||||
my_macro!();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
// macros2.rs
|
||||
// Make me compile! Scroll down for hints :)
|
||||
|
||||
fn main() {
|
||||
my_macro!();
|
||||
}
|
||||
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
my_macro!();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// macros3.rs
|
||||
// Make me compile, without taking the macro out of the module! Scroll down for hints :)
|
||||
|
||||
#[macro_use]
|
||||
mod macros {
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
}
|
||||
};
|
||||
($val:expr) => {
|
||||
println!("Look at this other macro: {}", $val);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
|
||||
let vec1 = fill_vec(vec0);
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
|
||||
// Write a macro that passes the test! No hints this time, you can do it!
|
||||
|
||||
macro_rules! my_macro {
|
||||
($var:expr) => { //or just ("world!")
|
||||
"Hello world!"
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
if my_macro!("world!") != "Hello world!" {
|
||||
panic!("Oh no! Wrong output!");
|
||||
|
|
Loading…
Reference in a new issue