# มาโคร (Rust) > มาโครเชิงประกาศ (macro_rules!), derive macros, attribute macros, มาโครเชิงกระบวนการ, สุขลักษณะของมาโคร - 20 คำถามสัมภาษณ์ - Mid-Level - [คำถามสัมภาษณ์: Rust](https://sharpskill.dev/th/technologies/rust/interview-questions.md) ## 1. ไวยากรณ์ใดที่ใช้ในการกำหนด declarative macro ใน Rust? **คำตอบ** ไวยากรณ์ macro_rules! ใช้ในการกำหนด declarative macro ใน Rust รูปแบบ metaprogramming นี้ใช้ pattern matching บนไวยากรณ์ Rust เพื่อแปลงโค้ดในเวลาคอมไพล์ declarative macro ยังถูกเรียกว่า "macros by example" เพราะทำงานโดยการจับคู่รูปแบบและสร้างโค้ดจากรูปแบบเหล่านั้น ## 2. จะเรียกใช้มาโครใน Rust ได้อย่างไร? **คำตอบ** มาโครใน Rust ถูกเรียกใช้ด้วยเครื่องหมายอัศเจรีย์หลังชื่อ ตามด้วยอาร์กิวเมนต์ในวงเล็บ วงเล็บเหลี่ยม หรือวงเล็บปีกกา ข้อกำหนดนี้ช่วยให้แยกแยะการเรียกมาโครจากการเรียกฟังก์ชันปกติได้ด้วยสายตา ตัวอย่างเช่น println!("Hello") หรือ vec![1, 2, 3] เป็นการเรียกใช้มาโคร ## 3. ใช้ fragment specifier ใดเพื่อจับ expression ใน declarative macro? **คำตอบ** fragment specifier $e:expr จับ expression ของ Rust ใน declarative macro fragment specifier กำหนดประเภทของไวยากรณ์ที่มาโครสามารถรับได้ specifier ทั่วไปอื่น ๆ ได้แก่ ident สำหรับ identifier, ty สำหรับ type, tt สำหรับ token tree และ block สำหรับบล็อกโค้ด ## มีอีก 17 คำถาม - ความแตกต่างหลักระหว่าง declarative macro กับ procedural macro คืออะไร? - macro hygiene ใน Rust คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Rust อื่นๆ - [พื้นฐาน Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/rust-basics.md): 25 คำถาม, Junior - [Ownership & Borrowing](https://sharpskill.dev/th/technologies/rust/interview-questions/ownership-borrowing.md): 22 คำถาม, Junior - [Structs & Enums](https://sharpskill.dev/th/technologies/rust/interview-questions/structs-enums.md): 20 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/rust/interview-questions/error-handling.md): 18 คำถาม, Junior - [คอลเลกชัน](https://sharpskill.dev/th/technologies/rust/interview-questions/collections.md): 20 คำถาม, Junior - [โมดูลและแพ็กเกจ](https://sharpskill.dev/th/technologies/rust/interview-questions/modules-packages.md): 18 คำถาม, Junior - [Traits](https://sharpskill.dev/th/technologies/rust/interview-questions/traits.md): 22 คำถาม, Mid-Level - [Generics](https://sharpskill.dev/th/technologies/rust/interview-questions/generics.md): 20 คำถาม, Mid-Level - [Lifetimes](https://sharpskill.dev/th/technologies/rust/interview-questions/lifetimes.md): 20 คำถาม, Mid-Level - [Iterators & Closures](https://sharpskill.dev/th/technologies/rust/interview-questions/iterators-closures.md): 22 คำถาม, Mid-Level - [Smart Pointers](https://sharpskill.dev/th/technologies/rust/interview-questions/smart-pointers.md): 22 คำถาม, Mid-Level - [Concurrency Basics](https://sharpskill.dev/th/technologies/rust/interview-questions/concurrency-basics.md): 20 คำถาม, Mid-Level - [async/await](https://sharpskill.dev/th/technologies/rust/interview-questions/async-await.md): 22 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/rust/interview-questions/testing.md): 18 คำถาม, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/th/technologies/rust/interview-questions/cargo-ecosystem.md): 18 คำถาม, Mid-Level - [Pattern Matching](https://sharpskill.dev/th/technologies/rust/interview-questions/pattern-matching.md): 18 คำถาม, Mid-Level - [Serde และการ Serialization](https://sharpskill.dev/th/technologies/rust/interview-questions/serde-serialization.md): 20 คำถาม, Mid-Level - [Unsafe Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/unsafe-rust.md): 20 คำถาม, Senior - [Trait ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-traits.md): 22 คำถาม, Senior - [Lifetime ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-lifetimes.md): 20 คำถาม, Senior - [Type System](https://sharpskill.dev/th/technologies/rust/interview-questions/type-system.md): 20 คำถาม, Senior - [Tokio & Async I/O](https://sharpskill.dev/th/technologies/rust/interview-questions/tokio-async.md): 22 คำถาม, Senior - [การเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/rust/interview-questions/performance-optimization.md): 20 คำถาม, Senior - [Memory Management](https://sharpskill.dev/th/technologies/rust/interview-questions/memory-management.md): 20 คำถาม, Senior - [Web Frameworks](https://sharpskill.dev/th/technologies/rust/interview-questions/web-frameworks.md): 22 คำถาม, Senior - [Database Integration](https://sharpskill.dev/th/technologies/rust/interview-questions/database-integration.md): 20 คำถาม, Senior - [Design Pattern ของ Rust](https://sharpskill.dev/th/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/th/technologies/rust/interview-questions/macros