Say I have an enum
where most of the options have a value of the same type, but one or two don't. I I'd like to format the enum
by pattern matching all the options that have values... how do I do that? For example:
pub enum Error {
SUCCESS,
INVALID_PARAM(&'static str),
NOT_FOUND(&'static str),
BUSY(&'static str),
OTHER(&'static str)
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::SUCCESS => write!(f, "SUCCESS"),
Error::_(s) => write!(f, "{}", s), // <- this doesn't work, but I'd like something like it
}
}
}
Is there a way to pattern match against all options of an enum
that have the same type like this?