My use-case requires custom trait implementations (currently achieved via a derive macro and custom attributes). I’m not sure your structural records accomplish that. Currently I use a macro to generate code like this:
{
#[my_attr(...)]
#[derive(Clone, Debug, MyTrait)]
struct AnonStruct<A: MyTrait> {
fixed_field: u8,
gen_field: A,
}
impl<A: MyTrait> AnonStruct {
// custom impls passed into macro
}
AnonStruct {
fixed_field: 0,
gen_field: field_val, // passed into macro by user
}
}
Locally the struct has a name, but effectively the macro just returns an anonymous type with some trait bounds.
This approach works, except that within the impls the type of gen_field
is merely A: MyTrait
, which makes it more difficult to use than necessary.
(Actually, I already have support for explicit typing by the user, but as mentioned that’s not always possible due to use of closures and often not simple.)