Module frunk_core::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); // doneRunTraits
- A trait that converts from a type to a generic representation.
Functions
- Converts one type
Srcinto another typeDstassuming they have the same representation typeRepr. - Given a generic representation
Reprof aDst, returnsDst. - Given a value of type
Src, returns its generic representationRepr. - Maps a value of a given type
Originusing a function on a typeInterwhich has the same representation type ofOrigin. - Maps a value of a given type
Originusing a function on the representation typeReprofOrigin.