From 5db93c5962fb2fc65c26f2cc9f6875414c43b697 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 10 Jan 2019 23:46:36 +0000 Subject: Implement Display for the Error enum --- src/error.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/error.rs b/src/error.rs index 6e32155..6872382 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,7 @@ // Copyright (C) 2019 Robin Krahl // SPDX-License-Identifier: MIT +use std::fmt; use std::io; use std::process; use std::result; @@ -21,6 +22,16 @@ pub enum Error { Utf8Error(str::Utf8Error), } +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + Error::Error(ref s) => write!(f, "Error: {}", s), + Error::IoError(ref e) => write!(f, "I/O error: {}", e), + Error::Utf8Error(ref e) => write!(f, "UTF-8 error: {}", e), + } + } +} + impl From<&str> for Error { fn from(string: &str) -> Error { Error::Error(string.to_string()) -- cgit v1.2.1