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 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
DestinationType
This parameter is mandatory and have to be present in the To struct attribute.
Generics
You can specify destination type with generics, these generics should be compatible with the fields of your src struct :
Field
Optional parameter, target the destination type field
With
Optional parameter, provide a function to transform the annotated field to the destination field. Signature of the function should be :
Generics
You can use generics in your function if the generic types constraint respect the source field type and destination field type :
License: MIT OR Apache-2.0