cons_cell 0.1.0

Swiss knife for heterogenous containers
Documentation
use crate::cons::traits::does_not_contain::DoesNotContain;
use crate::cons::{Cons, ConsCell, Nil};
use typenum_uuid_trait::TypeId;

pub trait Distinct: ConsCell {}

impl<C: Cons> Distinct for C
where
    <C as Cons>::Head: TypeId,
    C::Tail: DoesNotContain<C::Head>,
    C::Tail: Distinct,
{
}

impl<NilSeed> Distinct for Nil<NilSeed> {}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::cons::ConsCell;
    use crate::cons::test_types::*;
    use crate::cons::types::hcons::HNil;

    fn only_distinct<C: ConsCell + Distinct>(_: C) {}
    #[test]
    fn it_works() {
        let c = HNil::new().extend(U8(1)).extend(U32(2));
        only_distinct(HNil::new());
        only_distinct(c);

        // Does not compile
        // let repeated_c = HNil::new()
        //     .extend(U8{val:1u8})
        //     .extend(U32{val:2u32})
        //     .extend(U8{val:3u8});
        // only_distinct(repeated_c);
    }
}