trait definition and struct-tuple example

This commit is contained in:
vegowotenks 2025-05-02 19:38:30 +02:00
commit 1a43c2d1a5
7 changed files with 112 additions and 0 deletions

21
src/instances.rs Normal file
View 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)
}
}