strum
strum copied to clipboard
Visibility for EnumIter
It seems currently the struct generated from #[derive(EnumIter)]
propagates the visibility from the original enum. Is it possible to have this configurable?
This was mentioned in an early comment and it seems like we have precedent for this in other macros.
A work around I've been using is wrapping my enum in an mod inner { ... }
and re-exporting what I want to be public with pub use inner::MyEnum
I think this triggers a warning/error if you do this? Are you suggesting something like this (playground link)?
Unlike EnumDiscriminants, IntoEnumIterator
implements a trait on your enum type which means the iterator type needs to be at least as visible as the Enum type itself.
Okay yeah, I do get an error when I'm missing the same visibility as the enum type.
I tried to experiment with having IntoEnumIterator::iter
return an opaque type (e.g. fn iter() -> impl Iterator<Item = Enum>
) to further hide the generated EnumIter but that's not currently possible in trait definitions.
I guess we can technically force privacy and get rid of the error by redeclaring an entirely new trait within the module (playground link), but this starts becoming an unfortunate workaround
It unfortunately does get increasingly awkward to work around. While I think more flexibility is nice, I don't think rust really has the features we need to implement this properly at the moment (not to mention the back-compact difficulties) so I'm going to suggest we hold off making any changes, but I do appreciate the discussion.