Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 151 forks source link

Add EnumDiscriminants Trait and related Macro impl #377

Closed vpochapuis closed 1 month ago

vpochapuis commented 2 months ago

This PR has for goal to implement and resolve https://github.com/Peternator7/strum/issues/376 as well as https://github.com/Peternator7/strum/pull/176

yescallop commented 1 month ago

I should note that these changes break the following user code:

#[derive(EnumDiscriminants)]
#[strum_discriminants(name(PrivateDiscriminants), vis(pub(self)))]
pub enum PublicEnum {
    Variant0(bool),
    Variant1 { a: bool },
}

The error message is:

error[E0446]: private type `PrivateDiscriminants` in public interface

This is because the IntoDiscriminant impl of PublicEnum leaks the private PrivateDiscriminants type. Should we maybe exclude the IntoDiscriminant impl when the parent enum is public and the generated enum is private?