coproduct

Crates.iocoproduct
lib.rscoproduct
version0.4.1
sourcesrc
created_at2022-09-26 15:32:50.222447
updated_at2022-10-08 19:59:22.945519
descriptionGeneric coproduct type with minimal memory footprint
homepage
repositoryhttps://github.com/joonazan/coproduct
max_upload_size
id674312
size33,983
Joonatan Saarhelo (joonazan)

documentation

https://docs.rs/coproduct

README

Coproduct

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.

Commit count: 45

cargo fmt