Avatar ·

Comment voir la macro développée qui provoque une erreur de compilation en Rust ?

Je suis débutant en Rust et j'essaie d'utiliser des macros pour générer du code. J'ai pris la crate populaire `serde` et écrit ce code : ```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); } ``` Tout fonctionne. Mais quand j'ai essayé d'écrire ma propre macro pour implémenter automatiquement un 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({}, {})"); ```