Trait frunk_core::generic::Generic
[−]
[src]
pub trait Generic { type Repr; fn into(self) -> Self::Repr; fn from(r: Self::Repr) -> Self; fn convert_from<A>(a: A) -> Self where A: Generic<Repr=Self::Repr>, Self: Sized { ... } }
A trait that converts from a type to a generic representation
For the most part, you should be using the derivation that is available through frunk_derive to generate instances of this typeclass for your types.
I would highly recommend you check out derivation_tests.rs
to see how to actually use
this trait in real life. Since frunk_derive depends on this trait, I can't actually
pull it in as a dependency here (otherwise the dependency would be circular) and show
how to use it in a proper doc test.
#[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 { first_name: "Joe", last_name: "Blow", age: 30, }; let d_person: DomainPerson = convert_from(a_person); // doneRun
Associated Types
type Repr
The generic representation type
Required Methods
fn into(self) -> Self::Repr
Go from something to Repr
fn from(r: Self::Repr) -> Self
Go from Repr to something
Provided Methods
fn convert_from<A>(a: A) -> Self where A: Generic<Repr=Self::Repr>, Self: Sized
From one type to another using a type with a compatible generic representation