Crates.io | small_iter_fields |
lib.rs | small_iter_fields |
version | 0.1.5 |
source | src |
created_at | 2024-08-10 20:42:31.063764 |
updated_at | 2024-09-25 13:16:55.143193 |
description | get an iterator, or get the length, or convert to a hashmap from an enum |
homepage | |
repository | https://github.com/Ike-l/iter_fields |
max_upload_size | |
id | 1332697 |
size | 6,892 |
This crate adds #[derive(IterFields)]
, #[derive(LenFields)]
and #[derive(HashFields)]
.
It works for:
use std::collections::HashMap;
use small_iter_fields::{IterFields, LenFields, HashFields};
#[derive(IterFields, LenFields, HashFields, Hash, PartialEq, Eq)]
enum Stage {
Start,
Middle,
End,
}
let mut vec: Vec<Stage> = Vec::with_capacity(Stage::len());
assert!(vec.capacity() >= 3);
for stage in Stage::iter_fields() {
vec.push(stage);
};
assert!(vec.contains(&Stage::Start));
assert!(vec.contains(&Stage::Middle));
assert!(vec.contains(&Stage::End));
let map: HashMap<Stage, Vec<i32>> = Stage::to_hashmap(Vec::new());
assert!(map.capacity() >= 3);
assert_eq!(map.get(&Stage::Start), Some(&Vec::new()));
MIT or Apache-2.0