use pyo3::pyclass; use pyo3_special_method_derive::{Dir, Repr, Str}; #[pyclass] #[derive(Str, Repr, Dir)] enum Tester { #[pyo3_smd_repr(skip)] Alpha { x: u32, }, Beta { x: u32, y: u32, }, #[pyo3_smd_str(skip)] Gamma { x: u32, y: u32, z: u32, }, } #[pyclass] #[derive(Dir, Str, Repr)] #[allow(dead_code)] struct Person { pub name: String, #[pyo3_smd_repr(skip)] pub occupation: String, #[pyo3_smd_str(skip)] pub phone_num: String, } fn main() { let person = Person { name: "John Doe".to_string(), occupation: "Programmer".to_string(), phone_num: "123 456 7890".to_string(), }; assert_eq!( person.__dir__(), vec![ "name".to_string(), "occupation".to_string(), "phone_num".to_string() ] ); assert_eq!( person.__str__(), "Person(name=\"John Doe\", occupation=\"Programmer\")" ); assert_eq!( person.__repr__(), "Person(name=\"John Doe\", phone_num=\"123 456 7890\")" ); let tester_beta = Tester::Beta { x: 123, y: 456 }; assert_eq!( tester_beta.__dir__(), vec!["Alpha".to_string(), "Beta".to_string(), "Gamma".to_string()] ); assert_eq!(tester_beta.__str__(), "Tester.Beta(x=123, y=456)"); let tester_gamma = Tester::Gamma { x: 123, y: 456, z: 789, }; assert_eq!( tester_gamma.__dir__(), vec!["Alpha".to_string(), "Beta".to_string(), "Gamma".to_string()] ); assert_eq!(tester_gamma.__str__(), ""); let tester_alpha: Tester = Tester::Alpha { x: 123 }; assert_eq!( tester_alpha.__dir__(), vec!["Alpha".to_string(), "Beta".to_string(), "Gamma".to_string()] ); assert_eq!(tester_alpha.__repr__(), ""); }