attrsets
Have you ever wanted to, say, define
a few different
serde
serializations
for the same structures?
Well, you could always write two versions of a struct,
and std::mem::transmute
between them to get different serializations:
But that's unmaintainable! >_<
This procedural macro automates this process:
This example would basically expand into the above.
Every identifier in the attrsets
attribute defines a suffix for a
new version of the struct.
The attrset
field attribute wraps any other attribute,
only including it in the provided list of variants (comma separated).
Use _
for the plain non-suffixed variant e.g.:
Limitations
- errors are not nice
- no way to propagate the variant choices to nested structs yet
- of course you can just parameterize the structs and define nice aliases like
type PostR = PostReadable<ImageReadable<GeoReadable>>
- of course you can just parameterize the structs and define nice aliases like
License
This is free and unencumbered software released into the public domain.
For more information, please refer to the UNLICENSE
file or unlicense.org.