# マクロ (Rust) > 宣言的マクロ(macro_rules!)、derive マクロ、attribute マクロ、手続き的マクロ、マクロの衛生性 - 20 面接問題 - Mid-Level - [面接問題: Rust](https://sharpskill.dev/ja/technologies/rust/interview-questions.md) ## 1. Rust で宣言的マクロを定義するために使用される構文はどれですか? **回答** macro_rules! 構文は Rust で宣言的マクロを定義するために使用されます。このメタプログラミングの形式は、Rust 構文に対するパターンマッチングを使用してコンパイル時にコードを変換します。宣言的マクロは、パターンをマッチさせてそのパターンに基づいてコードを生成するため、「macros by example」とも呼ばれます。 ## 2. Rust でマクロを呼び出すにはどうしますか? **回答** Rust のマクロは名前の後に感嘆符を付け、続けて括弧、角括弧、または波括弧で引数を渡して呼び出します。この慣習により、マクロ呼び出しを通常の関数呼び出しと視覚的に区別できます。例えば println!("Hello") や vec![1, 2, 3] はマクロの呼び出しです。 ## 3. 宣言的マクロで式をキャプチャするにはどの fragment specifier を使いますか? **回答** fragment specifier $e:expr は宣言的マクロで Rust の式をキャプチャします。fragment specifier はマクロが受け付けられる構文の種類を定義します。その他のよく使われる specifier には、識別子用の ident、型用の ty、token tree 用の tt、コードブロック用の block があります。 ## さらに17問利用可能 - 宣言的マクロと手続き的マクロの主な違いは何ですか? - Rust におけるマクロの衛生性(macro hygiene)とは何ですか? 無料で登録: https://sharpskill.dev/ja/login ## その他のRust面接トピック - [Rustの基礎](https://sharpskill.dev/ja/technologies/rust/interview-questions/rust-basics.md): 25問, Junior - [Ownership & Borrowing](https://sharpskill.dev/ja/technologies/rust/interview-questions/ownership-borrowing.md): 22問, Junior - [Structs & Enums](https://sharpskill.dev/ja/technologies/rust/interview-questions/structs-enums.md): 20問, Junior - [エラー処理](https://sharpskill.dev/ja/technologies/rust/interview-questions/error-handling.md): 18問, Junior - [コレクション](https://sharpskill.dev/ja/technologies/rust/interview-questions/collections.md): 20問, Junior - [モジュールとパッケージ](https://sharpskill.dev/ja/technologies/rust/interview-questions/modules-packages.md): 18問, Junior - [Traits](https://sharpskill.dev/ja/technologies/rust/interview-questions/traits.md): 22問, Mid-Level - [Generics](https://sharpskill.dev/ja/technologies/rust/interview-questions/generics.md): 20問, Mid-Level - [Lifetimes](https://sharpskill.dev/ja/technologies/rust/interview-questions/lifetimes.md): 20問, Mid-Level - [Iterators & Closures](https://sharpskill.dev/ja/technologies/rust/interview-questions/iterators-closures.md): 22問, Mid-Level - [Smart Pointers](https://sharpskill.dev/ja/technologies/rust/interview-questions/smart-pointers.md): 22問, Mid-Level - [Concurrency Basics](https://sharpskill.dev/ja/technologies/rust/interview-questions/concurrency-basics.md): 20問, Mid-Level - [async/await](https://sharpskill.dev/ja/technologies/rust/interview-questions/async-await.md): 22問, Mid-Level - [Testing](https://sharpskill.dev/ja/technologies/rust/interview-questions/testing.md): 18問, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/ja/technologies/rust/interview-questions/cargo-ecosystem.md): 18問, Mid-Level - [Pattern Matching](https://sharpskill.dev/ja/technologies/rust/interview-questions/pattern-matching.md): 18問, Mid-Level - [Serde とシリアライゼーション](https://sharpskill.dev/ja/technologies/rust/interview-questions/serde-serialization.md): 20問, Mid-Level - [Unsafe Rust](https://sharpskill.dev/ja/technologies/rust/interview-questions/unsafe-rust.md): 20問, Senior - [高度なトレイト](https://sharpskill.dev/ja/technologies/rust/interview-questions/advanced-traits.md): 22問, Senior - [高度な lifetime](https://sharpskill.dev/ja/technologies/rust/interview-questions/advanced-lifetimes.md): 20問, Senior - [Type System](https://sharpskill.dev/ja/technologies/rust/interview-questions/type-system.md): 20問, Senior - [Tokio & Async I/O](https://sharpskill.dev/ja/technologies/rust/interview-questions/tokio-async.md): 22問, Senior - [パフォーマンス最適化](https://sharpskill.dev/ja/technologies/rust/interview-questions/performance-optimization.md): 20問, Senior - [Memory Management](https://sharpskill.dev/ja/technologies/rust/interview-questions/memory-management.md): 20問, Senior - [Web Frameworks](https://sharpskill.dev/ja/technologies/rust/interview-questions/web-frameworks.md): 22問, Senior - [Database Integration](https://sharpskill.dev/ja/technologies/rust/interview-questions/database-integration.md): 20問, Senior - [Rust デザインパターン](https://sharpskill.dev/ja/technologies/rust/interview-questions/design-patterns.md): 20問, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/ja/technologies/rust/interview-questions/macros