From aeaa001b385a5a786f5a26b546090e8d82e8fec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivica=20=C5=A0imi=C4=87?= <simicivica10@gmail.com> Date: Thu, 18 Jul 2019 12:59:46 +0200 Subject: [PATCH] macros and stuff --- exercises/macros/macros1.rs | 2 +- exercises/macros/macros2.rs | 8 +++----- exercises/macros/macros3.rs | 1 + exercises/macros/macros4.rs | 2 +- exercises/move_semantics/move_semantics1.rs | 2 +- exercises/test4.rs | 5 +++++ 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/exercises/macros/macros1.rs b/exercises/macros/macros1.rs index a7c78a5..2471126 100755 --- a/exercises/macros/macros1.rs +++ b/exercises/macros/macros1.rs @@ -8,7 +8,7 @@ macro_rules! my_macro { } fn main() { - my_macro(); + my_macro!(); } diff --git a/exercises/macros/macros2.rs b/exercises/macros/macros2.rs index bc2e56b..5c23efd 100755 --- a/exercises/macros/macros2.rs +++ b/exercises/macros/macros2.rs @@ -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!(); +} diff --git a/exercises/macros/macros3.rs b/exercises/macros/macros3.rs index 84c4308..71213d4 100755 --- a/exercises/macros/macros3.rs +++ b/exercises/macros/macros3.rs @@ -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 { () => { diff --git a/exercises/macros/macros4.rs b/exercises/macros/macros4.rs index d844bb0..9369ff5 100755 --- a/exercises/macros/macros4.rs +++ b/exercises/macros/macros4.rs @@ -4,7 +4,7 @@ macro_rules! my_macro { () => { println!("Check out my macro!"); - } + }; ($val:expr) => { println!("Look at this other macro: {}", $val); } diff --git a/exercises/move_semantics/move_semantics1.rs b/exercises/move_semantics/move_semantics1.rs index 37038ec..f75714b 100755 --- a/exercises/move_semantics/move_semantics1.rs +++ b/exercises/move_semantics/move_semantics1.rs @@ -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); diff --git a/exercises/test4.rs b/exercises/test4.rs index e50f1b0..e4468ff 100644 --- a/exercises/test4.rs +++ b/exercises/test4.rs @@ -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!");