macro_rules! foo_macro {
($name:ident) => {
pub struct $name;
}
}
/// Doc comment for Foo struct.
foo_macro!(Foo);
/// Doc comment for Bar struct.
foo_macro!(Bar);
μ΄ κ°λ¨ν μ½λ μνμμ μ¬μ©μλ 맀ν¬λ‘ νμ₯μ ν΅ν΄ ꡬ쑰체λ₯Ό λ§λ€κ³ λͺ¨λ λ€λ₯Έ 맀ν¬λ‘ νΈμΆμ λν΄ κ³ μ ν μ£Όμμ μμ±νλ €κ³ ν©λλ€.
μ΄κ²μ struct Foo λ° Barμ λν κ³ μ ν μ£Όμμ μλ―Έν©λλ€. μ΄λ νμ¬ Rust μ»΄νμΌλ¬μμ λ€μμ νμ±νν λ κ°λ₯νμ§ μμ΅λλ€.
#![warn(missing_docs)]
λ€μ κ²½κ³ μ ν¨κ»:
warning: missing documentation for a struct
--> src/activation_fn.rs:9:3
|
9 | pub struct $name;
| ^^^^^^^^^^^^^^^^^
...
14 | foo_macro!(Foo);
| ---------------- in this macro invocation
|
note: lint level defined here
--> src/lib.rs:1:9
|
1 | #![warn(missing_docs)]
| ^^^^^^^^^^^^
warning: missing documentation for a struct
--> src/activation_fn.rs:9:3
|
9 | pub struct $name;
| ^^^^^^^^^^^^^^^^^
...
17 | foo_macro!(Bar);
| ---------------- in this macro invocation
|
note: lint level defined here
--> src/lib.rs:1:9
|
1 | #![warn(missing_docs)]
| ^^^^^^^^^^^^
μ΄κ²μ λΆλͺ ν μλνμ§λ§:
macro_rules! foo_macro {
/// Unified comment for any macro expansion which is bad!
($name:ident) => {
pub struct $name;
}
}
foo_macro!(Foo);
foo_macro!(Bar);
λͺ¨λ μμ±(λ¬Έμ μ£Όμμ #[doc]
μμ±)μ μ λ¬ν μ μμ§λ§ μμ±μ λ°λ³΅ λ€μ identκ° μ§μ μ¬ μ μκΈ° λλ¬Έμ ꡬ문μ μ½κ° λ³κ²½ν΄μΌ ν©λλ€.
μ (λμ΄ν°)
macro_rules! foo_macro {
($(#[$attr:meta])* struct $name:ident) => {
$(#[$attr])*
pub struct $name;
}
}
foo_macro!(
/// Doc comment for Foo struct.
struct Foo
);
foo_macro!(
/// Doc comment for Bar struct.
struct Bar
);
fn main() {
}
μ¬μ©μ ν¬λΌμ μ΄μ κ°μ μ§λ¬Έμ λν΄ ν λ‘ ν μ μλ μ’μ μ₯μμ λλ€. https://users.rust-lang.org/
ꡬ체μ μΈ λ²κ·Έ λ³΄κ³ μλ μ¬κΈ°μμ λ§€μ° νμν©λλ€. κ·Έλ¬λ λ΅λ³μ΄ μλ£λμκ³ μ¬μ©μ ν¬λΌμμ μΆκ° ν λ‘ μ΄ κ°μ₯ μ’κΈ° λλ¬Έμ μ΄ κΈμ λ«κ² μ΅λλ€.
μ¬κΈ°μ λ¬Έμ κ° ν΄κ²°λμ§ μμ κ² κ°μ΅λλ€. ident
μμνλ 맀ν¬λ‘μ λν λ¬Έμ μ£Όμμ μμ±νλ λ°©λ²
κ°μ₯ μ μ©ν λκΈ
μ¬κΈ°μ λ¬Έμ κ° ν΄κ²°λμ§ μμ κ² κ°μ΅λλ€.
ident
μμνλ 맀ν¬λ‘μ λν λ¬Έμ μ£Όμμ μμ±νλ λ°©λ²