4 ms·
It can both be applied to enum variants as well as to entire enums. I meant the latter case. From the release announcement: > A perhaps more important aspect o
by est31 7y ago
It can both be applied to enum variants as well as to entire enums. I meant the latter case. From the release announcement:
> A perhaps more important aspect of #[non_exhaustive] is that it can also be attached to enums themselves. An example, taken from the standard library, is Ordering
For example, take this _Nonexhaustive enum case here: https://github.com/est31/rcgen/blob/d6b84d3d9d51b088dd672975e68dcbcc286e347a/src/lib.rs#L172 https://github.com/est31/rcgen/blob/d6b84d3d9d51b088dd672975...
A little bit further down, I'm matching on the enum in the to_oid function. I'd prefer if I got an error or at least a warning pointing to the match if I added a new enum case and didn't update the match statement.
- Nemo157 7y agonon_exhaustive only affects downstream code, within the crate you can still treat it exhaustively. For example in this playground[0] if you build in test mode the match works inside the crate, but fails in the doc-test because that is treated as external code. [0]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6ab1c7f5a94ca85915b114f97246b170 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- est31 7y agoOh that's an interesting point, I didn't know that. I guess I'll use #[non_exhaustive] then after all.