HNHacker News
TopNewBestAskShowJobs

ffminus

10 karma · joined March 3, 2025

submissionscomments
ffminus··on API design note: Beware of adding an "Other" enum value
It lets you have a middle ground, with the decision of when breaking happens left up to library users. Without non_exhaustive, all consumers always get your second scenario. With non_exhaustive, individual zoos get to pick their own policy of when/if animals should starve.

Each option has its place, it depends on context. Does the creator of the type want/need strictness from all their consumers, or can this call be left up to each consumer to make? The lint puts strictness back on the table as an opt-in for individual users.

ffminus··on API design note: Beware of adding an "Other" enum value
Library users can force a compile error when new variants get added, using a lint from rustc. It's "allow" by default, so it's opt-in.

https://doc.rust-lang.org/rustc/lints/listing/allowed-by-def...