mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-03 01:09:18 +00:00
commit
aab1c73495
@ -1,8 +1,8 @@
|
|||||||
// 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
|
// 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 {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
println!("Check out my macro!");
|
println!("Check out my macro!");
|
||||||
@ -10,5 +10,5 @@ macro_rules! my_macro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
my_macro();
|
my_macro!();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
// 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() {
|
fn main() {
|
||||||
my_macro!();
|
my_macro!();
|
||||||
}
|
}
|
||||||
|
#[macro_export]
|
||||||
macro_rules! my_macro {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
println!("Check out my macro!");
|
println!("Check out my macro!");
|
||||||
|
|||||||
@ -2,9 +2,9 @@
|
|||||||
// 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
|
//export works even with no pub mod
|
||||||
|
|
||||||
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,14 @@
|
|||||||
// 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() {
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
// modules1.rs
|
// modules1.rs
|
||||||
// Make me compile! Execute `rustlings hint modules1` for hints :)
|
// Make me compile! Execute `rustlings hint modules1` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
mod sausage_factory {
|
pub mod sausage_factory {
|
||||||
fn make_sausage() {
|
pub fn make_sausage() {
|
||||||
println!("sausage!");
|
println!("sausage!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
// modules2.rs
|
// modules2.rs
|
||||||
// Make me compile! Execute `rustlings hint modules2` for hints :)
|
// Make me compile! Execute `rustlings hint modules2` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
mod delicious_snacks {
|
pub mod delicious_snacks {
|
||||||
use self::fruits::PEAR as fruit;
|
pub use self::fruits::PEAR as fruit;
|
||||||
use self::veggies::CUCUMBER as veggie;
|
pub use self::veggies::CUCUMBER as veggie;
|
||||||
|
|
||||||
mod fruits {
|
mod fruits {
|
||||||
pub const PEAR: &'static str = "Pear";
|
pub const PEAR: &'static str = "Pear";
|
||||||
|
|||||||
@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
// Write a macro that passes the test! No hints this time, you can do it!
|
// 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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user