mapper

![github]![crates-io]![docs-rs]

This library provides a convenient derive macro for implementing [mapper_api::Mapper] trait and generate mapping without boilerplate.


Example

```rust use mapper::Mapper;

fn mapaccountid(accountid: &u16) -> String{ accountid.to_string() }

[derive(Mapper)]

[to(Person)]

struct User{ #[to(Person, field=name)] pub name: String, #[to(Person, with=mapaccountid)] pub accountid: u16, pub age: u8 } struct Person{ pub name: String, pub accountid: String, pub age: u8 } ```


Disclaimer

Default behavior

Default behavior is to take each field of annotated struct and clone those fields in the destination struct initializer : ```rust

[derive(Mapper)]

[to(Person)]

struct User{ pub name: String } struct Person{ pub name: String } Generate 🔄 : rust impl Mapper for User{ fn to(&self)->Person{ Person{name: self.name.clone()} } } ```

To struct attribute

To field attribute

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