use coproduct::{At, Coproduct, CopyableCoproduct, Count, Embed, IndexedDrop, Union}; trait Prepend { type With; } impl Prepend for Coproduct { type With = Coproduct>; } impl Prepend for CopyableCoproduct { type With = CopyableCoproduct>; } fn transformer(c: C) -> <>::Pruned as Prepend>::With where C: At, C::Pruned: Prepend + Embed<<>::Pruned as Prepend>::With, Indices>, <>::Pruned as Prepend>::With: At, I: Count, { match c.uninject() { Ok(x) => coproduct::inject(x as u32), Err(x) => x.embed(), } } fn main() { let x: Coproduct!(String, u8) = Coproduct::inject(8); dbg!(x.clone()); let y = transformer(x); dbg!(y); let x: CopyableCoproduct!(i32, u8) = CopyableCoproduct::inject(8); dbg!(x.clone()); let y = transformer(x); dbg!(y); }