-
-
Notifications
You must be signed in to change notification settings - Fork 329
Closed
Description
Here is the pattern I would like to document and recommend for use cases that require exhaustive matching (which is uncommon, but they exist):
match expr {
Expr::Array(e) => {...}
Expr::Assign(e) => {...}
...
Expr::Yield(e) => {...}
#[cfg(test)]
Expr::TestExhaustive => unimplemented!(),
#[cfg(not(test))]
_ => { /* some sane fallback */ }
}
This way we fail your tests but don't break your library when adding a variant. I believe this has all the benefits of an exhaustive enum and all the benefits of a nonexhaustive enum for only a little effort.
FYI @zerakun @phaylon @BurntSushi from the reddit thread.
FYI @mystor for brainstorming.
FYI @Centril because language support for nonexhaustive would need to have at least these benefits before I would want to pick it up.
Metadata
Metadata
Assignees
Labels
No labels