mapper
This library provides a convenient derive macro for implementing [mapper_api::Mapper] trait and generate mapping without boilerplate.
Example
use Mapper;
Disclaimer
- Macro works only on C style struct like : struct MyStruct{field: u8}
- Mapper doesn't handle generics
- Mapper doesn't handle nested properties
Default behavior
Default behavior is to take each field of annotated struct and clone those fields in the destination struct initializer :
Generate 🔄 :
To struct attribute
- You can specify multiple destination types in this attribute :
#[to(Animal, Vehicle)]
To field attribute
- You can put multiple to attribute by field
- Syntax of this attribute :
#[to(<DestinationType>, field=<destination_field>, with=<transformation_function>)]
- This attribute is forbidden if you use only
DestinationType
This parameter is mandatory and have to be present in the To struct attribute
Field
Optional parameter, target the destination type field
With
Optional parameter, provide a function to transform the annotated field to the destination field
License: MIT OR Apache-2.0