| Crates.io | coproduct |
| lib.rs | coproduct |
| version | 0.4.1 |
| created_at | 2022-09-26 15:32:50.222447+00 |
| updated_at | 2022-10-08 19:59:22.945519+00 |
| description | Generic coproduct type with minimal memory footprint |
| homepage | |
| repository | https://github.com/joonazan/coproduct |
| max_upload_size | |
| id | 674312 |
| size | 33,983 |
Have you ever found yourself in a situation where you'd like to have two enums where only a few variants differ? Usually that involves a lot of duplication and boilerplate. Not any more! Coproducts allow you to describe them and convert between them effortlessly!
use coproduct::{Coproduct, MkUnion, Union};
#[derive(Debug)]
struct A;
#[derive(Debug)]
struct B;
#[derive(Debug)]
struct C;
#[derive(Debug)]
struct D;
type ABC = MkUnion!(A, B, C);
fn main() {
let abc: Coproduct<ABC> = Coproduct::inject(A);
let abcd: Coproduct<Union<D, ABC>> = abc.embed();
println!("{:?}", abcd);
}
Find out more in the documentation.