mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-28 14:59:18 +00:00
翻譯
This commit is contained in:
parent
28b05c6d26
commit
2e9f8188fe
@ -1,14 +1,10 @@
|
||||
# Macros
|
||||
# 巨集(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.
|
||||
Rust 的巨集系統非常強大,但也有點難以理解。我們不會教您如何編寫自己的全功能巨集。相反,我們將向您展示如何使用和創建它們。
|
||||
|
||||
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.
|
||||
如果您想了解更多關於編寫自己巨集的知識,可以參考 [macrokata](https://github.com/tfpk/macrokata) 專案,它的練習風格類似於 Rustlings,但專注於學習編寫巨集。
|
||||
|
||||
## Further information
|
||||
## 進一步了解
|
||||
|
||||
- [Macros](https://doc.rust-lang.org/book/ch19-06-macros.html)
|
||||
- [巨集](https://doc.rust-lang.org/book/ch19-06-macros.html)
|
||||
- [The Little Book of Rust Macros](https://veykril.github.io/tlborm/)
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
// macros1.rs
|
||||
//
|
||||
// Execute `rustlings hint macros1` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
// 執行 `rustlings hint macros1` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
println!("看看我的巨集!");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// macros2.rs
|
||||
//
|
||||
// Execute `rustlings hint macros2` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
// 執行 `rustlings hint macros2` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@ -11,6 +10,6 @@ fn main() {
|
||||
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
println!("看看我的巨集!");
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
// 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.
|
||||
// 執行 `rustlings hint macros3` 或使用 `hint` watch 子命令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
mod macros {
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
println!("看看我的巨集!");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,16 @@
|
||||
// macros4.rs
|
||||
//
|
||||
// Execute `rustlings hint macros4` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
// 執行 `rustlings hint macros4` 或使用 `hint` watch 子指令來獲取提示。
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[rustfmt::skip]
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
println!("看看我的巨集!");
|
||||
}
|
||||
($val:expr) => {
|
||||
println!("Look at this other macro: {}", $val);
|
||||
println!("看看這個其他的巨集: {}", $val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user