aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-10 23:46:36 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-11 00:49:35 +0100
commit5db93c5962fb2fc65c26f2cc9f6875414c43b697 (patch)
treee28102978346df72fb16a90572331c03f3ce99eb
parent3e7464c0f8cbadb8c6335c53579ec9570962dc3f (diff)
downloaddialog-rs-5db93c5962fb2fc65c26f2cc9f6875414c43b697.tar.gz
dialog-rs-5db93c5962fb2fc65c26f2cc9f6875414c43b697.tar.bz2
Implement Display for the Error enum
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/error.rs11
2 files changed, 12 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c4e1d97..833930d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# Unreleased
- Add the `Password` dialog box.
- Add the `Zenity` backend.
+- Implement `std::fmt::Display` for the `Error` enum.
# v0.1.0 (2019-01-08)
- Initial release with the `Input`, `Message` and `Question` dialog boxes and
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 <robin.krahl@ireas.org>
// 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())