automapper 0.0.2

A simple convention based object-to-object mapper for Rust
Documentation
  • Coverage
  • 33.33%
    2 out of 6 items documented1 out of 5 items with examples
  • Size
  • Source code size: 23.31 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.12 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 24s Average build duration of successful builds.
  • all releases: 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • mustakimali/automapper
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mustakimali

automapper

A convention based object-object mapper for Rust. This uses Json rustdoc generated by cargo doc.

Usage

Step 1: Generate rustdoc.json using automapper-cli.

# instal
cargo install --locked automapper-cli

# generate rustdoc.json in the root of a crate where you plan to use automapper
automapper-cli .

Step 2: Use automapper in your crate.

Define some types and use automapper to map between them.

// some types
pub struct SourceStruct {
    pub a: i32,
    pub b: u32,
    pub s: String,
}

pub struct DestStruct {
    pub a: i32,
    pub b: u32,
    pub s: String,
}

Use automapper using auto implemented trait [AutoMapsTo] and [AutoMapsFrom]

automapper::map!(SourceStruct, DestStruct);

use automapper::{AutoMapsFrom, AutoMapsTo};
let input = SourceStruct { .. };

let output = DestStruct::map_from(input); // using AutoMapsFrom trait
let output: DestStruct = input.map_into(); // using AutoMapsTo trait
let output = input.map_into(); // using AutoMapsTo trait (type annotation isn't necessary)

Or, Use automapper to generate mapping function

automapper::impl_map_fn!{
   fn convert_to(SourceStruct -> DestStruct);
}

// this generates `convert_to` function like this
// fn convert_to(value: SourceStruct) -> DestStruct { .. }

let input = SourceStruct { .. };
let output = convert_to(input);
// output is DestStruct { .. }