Crates.io | field_iterator |
lib.rs | field_iterator |
version | 0.1.0 |
source | src |
created_at | 2024-04-10 16:21:41.209266 |
updated_at | 2024-04-10 16:21:41.209266 |
description | A derivable trait for iterating over the fields of a struct. |
homepage | |
repository | https://github.com/HoloTheDrunk/field_iterator |
max_upload_size | |
id | 1203759 |
size | 5,871 |
Based on the abandoned struct_iterable. The rest of the README is taken from it.
This is meant as a lighter alternative to fields-iter.
First, add the crate to your Cargo.toml
:
[dependencies]
field_iterator = "0.1.1"
Next, include the library at the top of your Rust file:
use field_iterator::Iterable;
Finally, add the #[derive(Iterable)]
attribute to your struct:
#[derive(Iterable)]
struct MyStruct {
field1: u32,
field2: String,
// etc.
}
Now, you can iterate over the fields of an instance of your struct:
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);
}
If you're interested in contributing, please feel free to submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
This crate is distributed under an MIT license.