| Crates.io | enum-field |
| lib.rs | enum-field |
| version | 0.2.0 |
| created_at | 2025-09-29 09:46:29.582545+00 |
| updated_at | 2025-10-01 10:58:59.891155+00 |
| description | Declarative macros for enum-based heterogeneous field accessors. |
| homepage | |
| repository | https://github.com/dzmitry-lahoda/enum-field |
| max_upload_size | |
| id | 1859305 |
| size | 13,605 |
Given
enum AB { A, B }
enum XY { X, Y }
struct Product {
pub a_x : String,
pub a_y : u8,
pub b_x : String,
pub b_y : u8,
}
allows to
use AB::*;
use XY::*;
let product = Product { b_x: "b_x".to_string(), a_y: 2, .. };
let item = enum_field_use!(product . B _ X);
assert_eq!(item, "bx");
let item = enum_field_match_ab(&product. A _ X, |x| println!("{x}"));
in a generic way via a declarative macro, so that:
AB and XY enums could be in different crates
mut variants for field accessors
AB and XY can be up to 3 variants each and above
fields can be different (heterogeneous) return types
works on latest stable
but:
MyStruct::from) for each field type
Can functional crates in Rust do the above?