Support infallible EnumString for enums with a default variant#432
Open
scovich wants to merge 2 commits intoPeternator7:masterfrom
Open
Support infallible EnumString for enums with a default variant#432scovich wants to merge 2 commits intoPeternator7:masterfrom
scovich wants to merge 2 commits intoPeternator7:masterfrom
Conversation
scovich
added a commit
to delta-io/delta-kernel-rs
that referenced
this pull request
Feb 19, 2026
## What changes are proposed in this pull request? There's a semantic gap in strum's `EnumString`: The parsing API it derives is always fallible (impl `FromString` and `TryFrom`, both with strum parsing error), but enums with a default variant have infallible parsing (because any unknown value goes into the default). Define and use a new trait, `IntoTableFeature`, which mimicks `Into`. We can't "just" impl From for TableFeature because the blanket `impl<T: From> TryFrom for T` conflicts with the `impl TryFrom for TableFeature` strum emits. Result: Code that works with table features no longer needs to parse+unwrap, and there's now a narrow waist to update some day if/when this gets fixed upstream (just remove the extension trait and `impl From for TableFeature` instead). See also * Peternator7/strum#430 * Peternator7/strum#432 ## How was this change tested? Updated unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Any enum with a
#[strum(default)]variant has infallible parsing in practice, but the compiler does not know this because the error type is stillstrum::ParseError.This PR proposes a non-breaking change to address the issue: Define a new type-level attribute
parse_infallible, which instructsEnumStringto usestd::convert::InfallibleforFromStr::Err, and to deriveFrom<&str>(always) instead ofTryFrom<&str>(1.34+). This allows e.g.and (in 1.82+)
Existing
EnumStringderivations remain unchanged unless the user adds theparse_infallibleattribute. As a future breaking change, we could start inferringparse_infallibleautomatically even for enums that do not carry the annotation. If a breaking change is immediately acceptable, we don't need to define the new attribute at all, and this PR becomes simpler.NOTE:
TryFromis still available (for 1.34+) withparse_infallible, because theFrom<&str>derived byEnumStringactivates a blanket implementation of reverseInto, which in turn activates a blanket implementation ofTryFrom.Also update docs and add new unit tests that exercise infallible parsing for both normal and PHF enums.
Fixes #307