cons_cell 0.1.0

Swiss knife for heterogenous containers
Documentation
use crate::cons::traits::distinct::Distinct;
use crate::cons::traits::not_equal_unordered::NotEqualUnordered;
use crate::cons::{Cons, ConsCell, Nil};

pub trait DoesNotContainEqualUnordered<Contained: ConsCell + Distinct>: ConsCell {}

impl<ContainersCons: Cons, Contained: ConsCell + Distinct> DoesNotContainEqualUnordered<Contained>
    for ContainersCons
where
    ContainersCons::Head: ConsCell + Distinct,
    ContainersCons::Head: NotEqualUnordered<Contained>,
    ContainersCons::Tail: DoesNotContainEqualUnordered<Contained>,
{
}

impl<NilSeed, Contained: ConsCell + Distinct> DoesNotContainEqualUnordered<Contained>
    for Nil<NilSeed>
{
}

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

    fn only_does_not_contain_equal_unordered<Container: ConsCell, Contained: ConsCell + Distinct>(
        _: &Container,
    ) where
        Container: DoesNotContainEqualUnordered<Contained>,
    {
    }

    #[test]
    fn it_works() {
        let a = HNil::new().extend(U8(1)).extend(U16(2)).extend(U32(3));
        let b = HNil::new().extend(U8(1)).extend(U16(2)).extend(U64(3));
        let c = HNil::new().extend(U8(1)).extend(U32(2)).extend(U64(3));

        let sc = HNil::new().extend(a).extend(b).extend(c);

        type NotContained = HCons<U16, HCons<U32, HCons<U64, HNil>>>;

        only_does_not_contain_equal_unordered::<_, NotContained>(&sc);
        // Does not compile
        //type ContainedUnordered = HCons<U16, HCons<U8, HCons<U32, HNil>>>;
        // only_does_not_contain_equal_unordered::<_, ContainedUnordered>(&sc);
    }
}