From 5b07baddf86bb9f13ef8c3787ad1cce630e9e7ca Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 12 Feb 2018 21:22:12 +0100 Subject: [PATCH] Add error convenience extension --- lib/core/libimagerror/src/lib.rs | 2 ++ lib/core/libimagerror/src/str.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 lib/core/libimagerror/src/str.rs diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs index 5a3ceda7..204250ac 100644 --- a/lib/core/libimagerror/src/lib.rs +++ b/lib/core/libimagerror/src/lib.rs @@ -39,3 +39,5 @@ extern crate error_chain; pub mod trace; pub mod iter; +pub mod str; + diff --git a/lib/core/libimagerror/src/str.rs b/lib/core/libimagerror/src/str.rs new file mode 100644 index 00000000..66105d61 --- /dev/null +++ b/lib/core/libimagerror/src/str.rs @@ -0,0 +1,31 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2018 the imag contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use std::error::Error; + +pub trait ErrFromStr { + fn err_from_str(self) -> Result; +} + +impl ErrFromStr for Result { + fn err_from_str(self) -> Result { + self.map_err(|e| format!("{}", e.description())) + } +} +