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
Features Wishlist
- Stop relying on panic and unwrap and use proper errors with spans
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: