Merge pull request from ZhiHanZ/exercise_ans

test4 macro module
This commit is contained in:
ZhiHanZ 2020-05-03 23:48:29 -07:00 committed by GitHub
commit aab1c73495
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 18 deletions

View file

@ -1,8 +1,8 @@
// macros1.rs
// Make me compile! Execute `rustlings hint macros1` for hints :)
// I AM NOT DONE
// I am a rooky in metaprogramming
// strongly recommend to read and practice on https://danielkeep.github.io/tlborm/book/README.html
macro_rules! my_macro {
() => {
println!("Check out my macro!");
@ -10,5 +10,5 @@ macro_rules! my_macro {
}
fn main() {
my_macro();
my_macro!();
}

View file

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

View file

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

View file

@ -1,15 +1,14 @@
// 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

@ -1,10 +1,9 @@
// modules1.rs
// Make me compile! Execute `rustlings hint modules1` for hints :)
// I AM NOT DONE
mod sausage_factory {
fn make_sausage() {
pub mod sausage_factory {
pub fn make_sausage() {
println!("sausage!");
}
}

View file

@ -1,11 +1,10 @@
// modules2.rs
// Make me compile! Execute `rustlings hint modules2` for hints :)
// I AM NOT DONE
mod delicious_snacks {
use self::fruits::PEAR as fruit;
use self::veggies::CUCUMBER as veggie;
pub mod delicious_snacks {
pub use self::fruits::PEAR as fruit;
pub use self::veggies::CUCUMBER as veggie;
mod fruits {
pub const PEAR: &'static str = "Pear";

View file

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