Getters By Type
This crate provides GettersByType and GettersMutByType derive macros for structs.
These derives implement a getter method for each type they contain.
Example using GettersByType :
let test = Test ;
// Let's sum all the i32 fields with a fold expression:
assert_eq!;
As you can notice, the getter methods return an array containing references to all the fields of the same type.
The GettersMutByType derive also adds a mut version for those methods.
Example using GettersMutByType :
let mut test = new;
// Let's update all the Updater fields
for updater in test.get_mut_fields_updater.iter_mut
Check more examples on the test file: tests/getters_by_type.rs
Usage
With Cargo, you can add this line to your Cargo.toml:
[]
= "*"
Development
This currently works with primitive types, and many other referencial and genecic types, such as &str or Vec, but there are cases that completely are not covered, like the trait objects. Want to contribute? Pull requests are always welcome. Because this is my first work with procedural macros, I guess thinks can improve a fair lot under the hood, so there should be a few low hanging fruits already. Let's go for them!
License
MIT