on it.
```rust,ignore (pseudo-Rust)
-use std::error::Error as StdError;
-
-#[non_exhaustive] pub enum Error {
- Message(String),
- Other,
+#[non_exhaustive]
+pub enum Error {
+ Message(String),
+ Other,
}
-impl StdError for Error {
- fn description(&self) -> &str {
+impl Display for Error {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
// This will not error, despite being marked as non_exhaustive, as this
// enum is defined within the current crate, it can be matched
// exhaustively.
- match *self {
- Message(ref s) => s,
- Other => "other or unknown error",
- }
- }
+ let display = match self {
+ Message(s) => s,
+ Other => "other or unknown error",
+ };
+ formatter.write_str(display)
+ }
}
```
// This will not error as the non_exhaustive Error enum has been matched with a
// wildcard.
match error {
- Message(ref s) => ...,
- Other => ...,
- _ => ...,
+ Message(s) => ...,
+ Other => ...,
+ _ => ...,
}
```