Type Definition itron_asp3::error::MaybeKind [−][src]
pub type MaybeKind = ();
This is supported on crate feature
unstable
only.Expand description
Placeholder for error kind variants.
Do not refer to this type in your code!
This type exists purely for documentation purposes. This type is replaced
with the inhabited type Kind
if the variant is valid for the current
target kernel or the uninhabited type Never
otherwise. This technique
lets us match against error kinds that do not exist in some kernels without
causing a compilation error.
#![feature(exhaustive_patterns)]
use itron::error::{Kind, Never};
enum ExampleError {
Error1(Kind),
Error2(Never),
// displayed as the following in the doc
// Error1(MaybeKind),
// Error2(MaybeKind),
}
// Portable code that handles all kinds
match error {
// `_` = don't care; the arm is just ignored if the
// error kind does not exist in this kernel
ExampleError::Error1(_) => println!("error1"),
ExampleError::Error2(_) => println!("error2"),
}
// Portable code that handles some kinds
match error {
ExampleError::Error2(_) => println!("error2"),
_ => println!("other"),
}
// Non-portable code that handles all kinds
match error {
// `Kind(_)` = assume that the error kind exists;
// raise a compile error if this assumption is broken
ExampleError::Error1(Kind(_)) => println!("error1"),
// (no arm) = assume that the error kind does not exist;
// raise a compile error if this assumption is broken
// (This requires `#[feature(exhaustive_patterns)]` for now.)
}