Skip to navigation
How to loop iterate a rust struct?
14.07.23
## You can not per se iterate a rust struct. * One way is to implement struct_iterable ```rust [dependencies] struct_iterable = "0.1.1" #[derive(Iterable)] struct MyStruct { field1: u32, field2: String, // etc. } let my_instance = MyStruct { field1: 42, field2: "Hello, world!".to_string(), }; for (field_name, field_value) in my_instance.iter() { println!("{}: {:?}", field_name, field_value); } ```
https://github.com/decomoraes/rust_struct_iterable
Reply
Anonymous
Information Epoch 1742188588
When in doubt, use brute force.
Home
Notebook
Contact us