trait definition and struct-tuple example
This commit is contained in:
commit
1a43c2d1a5
7 changed files with 112 additions and 0 deletions
21
src/instances.rs
Normal file
21
src/instances.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use crate::generic::{Field, Generic, Sum};
|
||||
|
||||
impl<A, B> Generic for (A, B) {
|
||||
type Representation = Sum<Field<A>, Field<B>>;
|
||||
|
||||
fn generalize(self) -> Self::Representation {
|
||||
let (l, r) = self;
|
||||
Sum {
|
||||
left: Field { value: l },
|
||||
right: Field { value: r }
|
||||
}
|
||||
}
|
||||
|
||||
fn specialize(rep: Self::Representation) -> Self {
|
||||
let Sum {
|
||||
left: Field { value: a },
|
||||
right: Field { value: b },
|
||||
} = rep;
|
||||
(a, b)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue