Module frunk::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
Run

Traits

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

Functions

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