summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagerror/src/io.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-03-07 17:31:30 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-03-07 17:31:30 +0100
commit00aa4df88edae1d5eeb3fb365af05f95bd0de3b4 (patch)
tree8e5bd3e4aa512fde4da1449ff3a578f084db5953 /lib/core/libimagerror/src/io.rs
parent10a7049639136cdcce0fad2209e631a21d00b595 (diff)
parent587af0ff0590307897a6d8c662c90a6e8b782212 (diff)
Merge branch 'cleanup-libimagerror'
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib/core/libimagerror/src/io.rs')
-rw-r--r--lib/core/libimagerror/src/io.rs62
1 files changed, 0 insertions, 62 deletions
diff --git a/lib/core/libimagerror/src/io.rs b/lib/core/libimagerror/src/io.rs
deleted file mode 100644
index 753fff6e..00000000
--- a/lib/core/libimagerror/src/io.rs
+++ /dev/null
@@ -1,62 +0,0 @@
-//
-// imag - the personal information management suite for the commandline
-// Copyright (C) 2015-2020 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::io::ErrorKind;
-
-use crate::exit::ExitCode;
-
-pub enum Settings {
- Ignore(ErrorKind),
- IgnoreAny(Vec<ErrorKind>),
-}
-
-pub trait ToExitCode<T> {
- fn to_exit_code(self) -> Result<T, ExitCode>;
- fn to_exit_code_with(self, _: Settings) -> Result<T, ExitCode>;
-}
-
-impl<T> ToExitCode<T> for Result<T, ::std::io::Error> {
-
- /// Returns an exit code of 0 if the error was a broken pipe, else 1
- fn to_exit_code(self) -> Result<T, ExitCode> {
- self.to_exit_code_with(Settings::Ignore(ErrorKind::BrokenPipe))
- }
-
- /// Returns an exit code depending on the settings
- ///
- /// Via the settings, errors can be ignores (translates to exit code zero). All other errors
- /// are translated into exit code 1
- ///
- fn to_exit_code_with(self, settings: Settings) -> Result<T, ExitCode> {
- self.map_err(move |e| match settings {
- Settings::Ignore(kind) => if e.kind() == kind {
- 0
- } else {
- 1
- },
- Settings::IgnoreAny(v) => if v.iter().any(|el| e.kind() == *el) {
- 0
- } else {
- 1
- },
- })
- .map_err(ExitCode::from)
- }
-
-}