From d59b50ccc97d3652f190a76b7b138643b55f664a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 6 Mar 2020 13:46:57 +0100 Subject: Remove unused iter extensions Signed-off-by: Matthias Beyer --- lib/core/libimagerror/src/iter.rs | 130 -------------------------------------- lib/core/libimagerror/src/lib.rs | 1 - 2 files changed, 131 deletions(-) delete mode 100644 lib/core/libimagerror/src/iter.rs diff --git a/lib/core/libimagerror/src/iter.rs b/lib/core/libimagerror/src/iter.rs deleted file mode 100644 index fa6fec1a..00000000 --- a/lib/core/libimagerror/src/iter.rs +++ /dev/null @@ -1,130 +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 failure::Error; - -/// An iterator that unwraps the `Ok` items of `iter`, while passing the `Err` items to its -/// closure `f`. -/// -/// This `struct` is created by the `unwrap_with()` method on `TraceIterator`. See its -/// documentation for more information. -#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] -#[derive(Clone)] -pub struct UnwrapWith{ - iter: I, - f: F -} - -impl Iterator for UnwrapWith - where - I: Iterator>, - F: FnMut(Error) -{ - type Item = T; - - #[inline] - fn next(&mut self) -> Option { - loop { - match self.iter.next() { - Some(Err(e)) => { (self.f)(e); }, - Some(Ok(item)) => return Some(item), - None => return None, - } - } - } -} - - - -/// Iterator helper for Unwrap with exiting on error -pub struct UnwrapExit(I) - where I: Iterator>; - -impl Iterator for UnwrapExit - where I: Iterator>, -{ - type Item = T; - - fn next(&mut self) -> Option { - use crate::trace::MapErrTrace; - self.0.next().map(|e| e.map_err_trace_exit_unwrap()) - } -} - -impl DoubleEndedIterator for UnwrapExit - where I: DoubleEndedIterator>, -{ - fn next_back(&mut self) -> Option { - use crate::trace::MapErrTrace; - self.0.next_back().map(|e| e.map_err_trace_exit_unwrap()) - } -} - -/// This trait provides methods that make it easier to work with iterators that yield a `Result`. -pub trait TraceIterator : Iterator> + Sized { - /// Creates an iterator that yields the item in each `Ok` item, while filtering out the - /// `Err` - /// items. Each filtered `Err` will be trace-logged with [`::trace::trace_error`]. - /// - /// As with all iterators, the processing is lazy. If you do not use the result of this method, - /// nothing will be passed to `::trace::trace_error`, no matter how many `Err` items might - /// be present. - #[inline] - fn trace_unwrap(self) -> UnwrapWith { - #[inline] - fn trace_error(err: Error) { - err.iter_chain().for_each(|cause| { - eprintln!("{}", cause); - }); - } - - self.unwrap_with(trace_error) - } - - /// Creates an iterator that yields the item in each `Ok` item. - /// - /// The first `Err(_)` element is traced using `::trace::trace_error_exit`. - /// - /// As with all iterators, the processing is lazy. If you do not use the result of this method, - /// nothing will be passed to `::trace::trace_error_exit`, no matter how many `Err` items might - /// be present. - #[inline] - fn trace_unwrap_exit(self) -> UnwrapExit { - UnwrapExit(self) - } - - - /// Takes a closure and creates an iterator that will yield the items inside all `Ok` items - /// yielded by the original iterator. All `Err` items will be filtered out, and the contents - /// of each `Err` will be passed to the closure. - /// - /// As with all iterators, the processing is lazy. The result of this method must be evaluated - /// for the closure to be called. - #[inline] - fn unwrap_with(self, f: F) -> UnwrapWith - where F: FnMut(Error) - { - UnwrapWith { iter: self, f } - } -} - -impl TraceIterator for I where - I: Iterator> -{} - diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs index 2358316c..fc3a33cf 100644 --- a/lib/core/libimagerror/src/lib.rs +++ b/lib/core/libimagerror/src/lib.rs @@ -43,7 +43,6 @@ extern crate failure; pub mod errors; pub mod exit; pub mod io; -pub mod iter; pub mod str; pub mod trace; -- cgit v1.2.3 From 2efb030c3d543b19cc358d47205c11123933a180 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 6 Mar 2020 13:48:25 +0100 Subject: Remove unused ExitUnwrap trait Signed-off-by: Matthias Beyer --- lib/core/libimagerror/src/exit.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/core/libimagerror/src/exit.rs b/lib/core/libimagerror/src/exit.rs index dd3c653b..3df64b2b 100644 --- a/lib/core/libimagerror/src/exit.rs +++ b/lib/core/libimagerror/src/exit.rs @@ -55,13 +55,3 @@ impl Error for ExitCode { } } -pub trait ExitUnwrap { - fn unwrap_or_exit(self) -> T; -} - -impl> ExitUnwrap for Result { - fn unwrap_or_exit(self) -> T { - self.map_err(Into::into).unwrap_or_else(|e| ::std::process::exit(e.0)) - } -} - -- cgit v1.2.3 From e770c79f53cee69dc42eb41d52adfb01501ba073 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 6 Mar 2020 13:49:31 +0100 Subject: Remove unused io error handling code Signed-off-by: Matthias Beyer --- lib/core/libimagerror/src/io.rs | 62 ---------------------------------------- lib/core/libimagerror/src/lib.rs | 1 - 2 files changed, 63 deletions(-) delete mode 100644 lib/core/libimagerror/src/io.rs 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), -} - -pub trait ToExitCode { - fn to_exit_code(self) -> Result; - fn to_exit_code_with(self, _: Settings) -> Result; -} - -impl ToExitCode for Result { - - /// Returns an exit code of 0 if the error was a broken pipe, else 1 - fn to_exit_code(self) -> Result { - 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 { - 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) - } - -} diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs index fc3a33cf..5b373b0b 100644 --- a/lib/core/libimagerror/src/lib.rs +++ b/lib/core/libimagerror/src/lib.rs @@ -42,7 +42,6 @@ extern crate failure; pub mod errors; pub mod exit; -pub mod io; pub mod str; pub mod trace; -- cgit v1.2.3 From 587af0ff0590307897a6d8c662c90a6e8b782212 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 6 Mar 2020 13:50:23 +0100 Subject: Remove unused str error handling module Signed-off-by: Matthias Beyer --- lib/core/libimagerror/src/lib.rs | 1 - lib/core/libimagerror/src/str.rs | 31 ------------------------------- 2 files changed, 32 deletions(-) delete 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 5b373b0b..55d045a6 100644 --- a/lib/core/libimagerror/src/lib.rs +++ b/lib/core/libimagerror/src/lib.rs @@ -42,6 +42,5 @@ extern crate failure; pub mod errors; pub mod exit; -pub mod str; pub mod trace; diff --git a/lib/core/libimagerror/src/str.rs b/lib/core/libimagerror/src/str.rs deleted file mode 100644 index 05842d6b..00000000 --- a/lib/core/libimagerror/src/str.rs +++ /dev/null @@ -1,31 +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::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| e.description().to_string()) - } -} - -- cgit v1.2.3