Como visualizar uma macro expandida que causa um erro de compilação em Rust?
Sou novo em Rust e estou tentando usar macros para gerar código. Peguei a crate popular `serde` e escrevi o seguinte código:
```rust
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct User {
name: String,
age: u32,
email: String,
}
fn main() {
let user = User {
name: "Alice".to_string(),
age: 30,
email: "alice@example.com".to_string(),
};
let json = serde_json::to_string(&user).unwrap();
println!("{}", json);
}
```
Funciona. Mas quando tentei escrever minha própria macro para implementação automática de trait:
```rust
macro_rules! impl_display {
($type:ty, $format:expr) => {
impl std::fmt::Display for $type {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, $format, self)
}
}
};
}
struct Point {
x: i32,
y: i32,
}
impl_display!(Point, "Point({}, {})");
```