# Macros (Rust) > Macros declarativas (macro_rules!), macros derive, macros de atributo, macros procedurais, higiene de macros - 20 perguntas de entrevista - Mid-Level - [Perguntas de entrevista: Rust](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista.md) ## 1. Qual é a sintaxe usada para definir uma macro declarativa em Rust? **Resposta** A sintaxe macro_rules! é usada para definir macros declarativas em Rust. Essa forma de metaprogramação usa pattern matching sobre a sintaxe Rust para transformar código em tempo de compilação. As macros declarativas também são chamadas de "macros by example" porque funcionam fazendo match de padrões e produzindo código baseado nesses padrões. ## 2. Como invocar uma macro em Rust? **Resposta** As macros em Rust são invocadas com um ponto de exclamação após o nome, seguido dos argumentos entre parênteses, colchetes ou chaves. Essa convenção permite distinguir visualmente as chamadas de macros das chamadas de funções normais. Por exemplo, println!("Hello") ou vec![1, 2, 3] são invocações de macros. ## 3. Qual fragment specifier usar para capturar uma expressão em uma macro declarativa? **Resposta** O fragment specifier $e:expr captura uma expressão Rust em uma macro declarativa. Os fragment specifiers definem o tipo de sintaxe que a macro pode aceitar. Outros specifiers comuns incluem ident para identificadores, ty para tipos, tt para um token tree e block para um bloco de código. ## Mais 17 perguntas disponiveis - Qual é a diferença principal entre macros declarativas e procedurais? - O que é a higiene de macros em Rust? Cadastre-se gratis: https://sharpskill.dev/pt/login ## Outros temas de entrevista Rust - [Fundamentos de Rust](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/rust-basics.md): 25 perguntas, Junior - [Ownership & Borrowing](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/ownership-borrowing.md): 22 perguntas, Junior - [Structs & Enums](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/structs-enums.md): 20 perguntas, Junior - [Tratamento de erros](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/error-handling.md): 18 perguntas, Junior - [Coleções](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/collections.md): 20 perguntas, Junior - [Módulos e Pacotes](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/modules-packages.md): 18 perguntas, Junior - [Traits](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/traits.md): 22 perguntas, Mid-Level - [Generics](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/generics.md): 20 perguntas, Mid-Level - [Lifetimes](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/lifetimes.md): 20 perguntas, Mid-Level - [Iterators & Closures](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/iterators-closures.md): 22 perguntas, Mid-Level - [Smart Pointers](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/smart-pointers.md): 22 perguntas, Mid-Level - [Concurrency Basics](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/concurrency-basics.md): 20 perguntas, Mid-Level - [async/await](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/async-await.md): 22 perguntas, Mid-Level - [Testing](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/testing.md): 18 perguntas, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/cargo-ecosystem.md): 18 perguntas, Mid-Level - [Pattern Matching](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/pattern-matching.md): 18 perguntas, Mid-Level - [Serde e serialização](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/serde-serialization.md): 20 perguntas, Mid-Level - [Unsafe Rust](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/unsafe-rust.md): 20 perguntas, Senior - [Traits avançados](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/advanced-traits.md): 22 perguntas, Senior - [Lifetimes Avançados](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/advanced-lifetimes.md): 20 perguntas, Senior - [Type System](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/type-system.md): 20 perguntas, Senior - [Tokio & Async I/O](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/tokio-async.md): 22 perguntas, Senior - [Otimização de Desempenho](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/performance-optimization.md): 20 perguntas, Senior - [Memory Management](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/memory-management.md): 20 perguntas, Senior - [Web Frameworks](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/web-frameworks.md): 22 perguntas, Senior - [Database Integration](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/database-integration.md): 20 perguntas, Senior - [Padrões de design em Rust](https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/design-patterns.md): 20 perguntas, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/pt/technologies/rust/perguntas-entrevista/macros