Skip to content

Conversation

@urkle
Copy link

@urkle urkle commented Oct 30, 2025

This resolves #165

This allows for having a default std derived Default than the fallback that num_enum uses for FromPrimitive

use num_enum::FromPrimitive;

#[derive(Default, FromPrimitive)]
#[repr(u8)]
enum MyFallbackEnum {
    #[default]
    Zero,
    #[num_enum(default)]
    NonZero,
}

assert_eq!(MyFallbackEnum::Zero, MyFallbackEnum::default());
assert_eq!(MyFallbackEnum::NonZero, 5u8.into());

#[derive(Default, FromPrimitive)]
#[repr(u8)]
enum MyCatchAllEnum {
    #[default]
    Zero,
    #[num_enum(catch_all)]
    NonZero(u8),
}

assert_eq!(MyFallbackEnum::Zero, MyFallbackEnum::default());
assert_eq!(MyFallbackEnum::NonZero(5u8), 5u8.into());

…_enum(catch_all)]

This allows for having a default std derived Default than the fallback that num_enum uses for FromPrimitive
@urkle
Copy link
Author

urkle commented Oct 30, 2025

@illicitonion if you want to do a breaking change for a 0.8.0 release we can

  1. drop ::num_enum::Default (not needed anymore IMO)
  2. rename #[num_enum(default] to #[num_enum(fallback)], and drop accepting #[default] as that is more clear as to the purpose and would reduce confusion with std #[default]. (or we emit warnings when those are used to allow a migration path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow #derive(Default) with catch_all

1 participant