Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Add Enum for tuples #13

Open
norcalli opened this issue Jun 15, 2022 · 1 comment
Open

Add Enum for tuples #13

norcalli opened this issue Jun 15, 2022 · 1 comment

Comments

@norcalli
Copy link

It seems logical that (A, B) where A: Enum, B: Enum would be basically the same as a struct's derivation, which is a cartesian product. I don't think we're allowed to implement this ourselves as tuples are always a foreign type, but it could be implemented for up to some length of tuples in the crate.

I personally want this so that I can produce enums via this utility function I've made:

#[inline(always)]
pub fn enum_iter<E: enum_map::Enum>() -> impl DoubleEndedIterator<Item = E> + Clone {
    (0..E::LENGTH).map(|i| E::from_usize(i))
}

without having to nest the enum_iter calls if there's multiple which I want to produce from.

(Side note: the enum_iter function might also be useful to have put in.)

I could make an MR if it's an amenable feature to include.

@KamilaBorowska
Copy link
Owner

I don't think this is possible to implement without generic_const_exprs nightly feature if I want to support enum maps of arbitrary types, and I have to no idea whether it would make sense to implement Enum only.

That said, a valid workaround if you know what enum cross-product you want would be define your own structure that holds both enums.

#[derive(Enum)]
struct Product(A, B);

Alternatively it's possible to nest enum maps: EnumMap<A, EnumMap<B, _>>.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants