structural-convert
Derive conversion traits when items are structurally similar.
Inspired by serde and struct-convert crates.
Features
- One to one fields mapping derive for
- From
- Into
- TryFrom
- TryInto
- Inner fields type conversion using
.into()/.try_into() - Rename enum variants and named fields
- Skip enum variants and named fields
- Fallback to default enum variant
- Named fields conversion fallback to default
- Enum not matched variants fallback to enum default
- Struct named fields only - Middle man type conversion using
asattribute - handles std types:
OptionResult- types from
std::collectionslike Vec, HashMap, etc...
Features Wishlist
- Implement attributes for unnamed fields (default, skip, as)
- Handle
TypetoOption<Type> - Add more data on try error and provide ability to inject your own error type
Examples
Check the tests folder for more examples, but here is some samples:
Struct
assert_eq!;
assert_eq!;
Generated code:
Enum
assert_eq!;
Generated code: