Module generic

Source
Expand description

This module holds the machinery behind Generic.

It contains the Generic trait and some helper methods for using the Generic trait without having to use universal function call syntax.

§Examples

use frunk::Generic;

#[derive(Generic)]
struct ApiPerson<'a> {
    FirstName: &'a str,
    LastName: &'a str,
    Age: usize,
}

#[derive(Generic)]
struct DomainPerson<'a> {
    first_name: &'a str,
    last_name: &'a str,
    age: usize,
}

let a_person = ApiPerson {
    FirstName: "Joe",
    LastName: "Blow",
    Age: 30,
};
let d_person: DomainPerson = frunk::convert_from(a_person); // done

Traits§

Generic
A trait that converts from a type to a generic representation.

Functions§

convert_from
Converts one type Src into another type Dst assuming they have the same representation type Repr.
from_generic
Given a generic representation Repr of a Dst, returns Dst.
into_generic
Given a value of type Src, returns its generic representation Repr.
map_inter
Maps a value of a given type Origin using a function on a type Inter which has the same representation type of Origin.
map_repr
Maps a value of a given type Origin using a function on the representation type Repr of Origin.