28 lines
619 B
Rust
28 lines
619 B
Rust
use crate::generic::{Field, Sum, Generic};
|
|
|
|
|
|
struct IntPair {
|
|
a: i32,
|
|
b: i32
|
|
}
|
|
|
|
impl Generic for IntPair {
|
|
type Representation = Sum<Field<i32>, Field<i32>>;
|
|
fn generalize(self) -> Self::Representation {
|
|
Sum {
|
|
left: Field { value: self.a },
|
|
right: Field { value: self.b }
|
|
}
|
|
}
|
|
fn specialize(rep: Self::Representation) -> Self {
|
|
let Sum {
|
|
left: Field { value: a },
|
|
right: Field { value: b },
|
|
} = rep;
|
|
IntPair { a, b }
|
|
}
|
|
}
|
|
|
|
fn convert(x: IntPair) -> (i32, i32) {
|
|
Generic::specialize(x.generalize())
|
|
}
|