cons_cell 0.1.0

Swiss knife for heterogenous containers
Documentation
use crate::cons::ConsCell;
use crate::cons::traits::distinct::Distinct;
use crate::cons::traits::switches::equal_unordered_switch::EqualUnorderedSwitch;
use typenum::True;
//TODO: Reason on whether we want to support this for types which are not distinct.

pub trait EqualUnordered<C: ConsCell + Distinct>: ConsCell + Distinct {}

impl<CA: ConsCell + Distinct, CB: ConsCell + Distinct> EqualUnordered<CB> for CA where
    CA: EqualUnorderedSwitch<CB, Value = True>
{
}

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

    fn eq_unordered_only<CA: ConsCell + Distinct, CB: ConsCell + Distinct + EqualUnordered<CA>>(
        _: CA,
    ) {
    }
    #[test]
    fn it_works() {
        let c = HNil::new().extend(U8(1)).extend(U32(2)).extend(U16(3));

        eq_unordered_only::<_, HCons<U8, HCons<U16, HCons<U32, HNil>>>>(c);

        // Does not compile
        // let repeated_c = HNil::new()
        //     .extend(U8(1))
        //     .extend(U32(2))
        //     .extend(U16(3));
        //
        // eq_unordered_only::<_, HCons<U64, HCons<U16, HCons<U32, HNil>>>>(c);
    }
}