field_iterator 0.1.0

A derivable trait for iterating over the fields of a struct.
Documentation
  • Coverage
  • 0%
    0 out of 6 items documented0 out of 3 items with examples
  • Size
  • Source code size: 5.38 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.13 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • HoloTheDrunk/field_iterator
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • HoloTheDrunk

Field iterator

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.

How to Use

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);
}

Limitations

  • Only structs with named fields are supported.

Contributing and License

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.