diff options
| author | Adam Brewer <adamhb321@gmail.com> | 2023-10-16 07:37:12 -0400 |
|---|---|---|
| committer | Adam Brewer <adamhb321@gmail.com> | 2023-10-16 07:37:12 -0400 |
| commit | 64d95837e9813541cf5b357de13865ce687ae98d (patch) | |
| tree | f022c5d5ba01128811c0b77618a7adb843ee876b /exercises/21_macros | |
| parent | c3941323e2c0b9ee286494327de92e00f23b9e3a (diff) | |
Update Exercises Directory Names to Reflect Order
Diffstat (limited to 'exercises/21_macros')
| -rw-r--r-- | exercises/21_macros/README.md | 14 | ||||
| -rw-r--r-- | exercises/21_macros/macros1.rs | 16 | ||||
| -rw-r--r-- | exercises/21_macros/macros2.rs | 16 | ||||
| -rw-r--r-- | exercises/21_macros/macros3.rs | 20 | ||||
| -rw-r--r-- | exercises/21_macros/macros4.rs | 21 |
5 files changed, 87 insertions, 0 deletions
diff --git a/exercises/21_macros/README.md b/exercises/21_macros/README.md new file mode 100644 index 0000000..337816d --- /dev/null +++ b/exercises/21_macros/README.md @@ -0,0 +1,14 @@ +# Macros + +Rust's macro system is very powerful, but also kind of difficult to wrap your +head around. We're not going to teach you how to write your own fully-featured +macros. Instead, we'll show you how to use and create them. + +If you'd like to learn more about writing your own macros, the +[macrokata](https://github.com/tfpk/macrokata) project has a similar style +of exercises to Rustlings, but is all about learning to write Macros. + +## Further information + +- [Macros](https://doc.rust-lang.org/book/ch19-06-macros.html) +- [The Little Book of Rust Macros](https://veykril.github.io/tlborm/) diff --git a/exercises/21_macros/macros1.rs b/exercises/21_macros/macros1.rs new file mode 100644 index 0000000..678de6e --- /dev/null +++ b/exercises/21_macros/macros1.rs @@ -0,0 +1,16 @@ +// macros1.rs +// +// Execute `rustlings hint macros1` or use the `hint` watch subcommand for a +// hint. + +// I AM NOT DONE + +macro_rules! my_macro { + () => { + println!("Check out my macro!"); + }; +} + +fn main() { + my_macro(); +} diff --git a/exercises/21_macros/macros2.rs b/exercises/21_macros/macros2.rs new file mode 100644 index 0000000..788fc16 --- /dev/null +++ b/exercises/21_macros/macros2.rs @@ -0,0 +1,16 @@ +// macros2.rs +// +// Execute `rustlings hint macros2` or use the `hint` watch subcommand for a +// hint. + +// I AM NOT DONE + +fn main() { + my_macro!(); +} + +macro_rules! my_macro { + () => { + println!("Check out my macro!"); + }; +} diff --git a/exercises/21_macros/macros3.rs b/exercises/21_macros/macros3.rs new file mode 100644 index 0000000..b795c14 --- /dev/null +++ b/exercises/21_macros/macros3.rs @@ -0,0 +1,20 @@ +// macros3.rs +// +// Make me compile, without taking the macro out of the module! +// +// Execute `rustlings hint macros3` or use the `hint` watch subcommand for a +// hint. + +// I AM NOT DONE + +mod macros { + macro_rules! my_macro { + () => { + println!("Check out my macro!"); + }; + } +} + +fn main() { + my_macro!(); +} diff --git a/exercises/21_macros/macros4.rs b/exercises/21_macros/macros4.rs new file mode 100644 index 0000000..71b45a0 --- /dev/null +++ b/exercises/21_macros/macros4.rs @@ -0,0 +1,21 @@ +// macros4.rs +// +// Execute `rustlings hint macros4` or use the `hint` watch subcommand for a +// hint. + +// I AM NOT DONE + +#[rustfmt::skip] +macro_rules! my_macro { + () => { + println!("Check out my macro!"); + } + ($val:expr) => { + println!("Look at this other macro: {}", $val); + } +} + +fn main() { + my_macro!(); + my_macro!(7777); +} |
