Revert "Add extension traits for handling Result<Option<T>, E> conversion"
This reverts commit d810b63886f4006d01bca894982bbc867616f37c. As resiter v0.4.0 does provide this extension now, we don't need it in the codebase anymore.
This commit is contained in:
parent
434f84c80d
commit
106be5746d
3 changed files with 0 additions and 85 deletions
|
@ -128,49 +128,3 @@ impl<I, T> TraceIterator<T> for I where
|
||||||
I: Iterator<Item = Result<T, Error>>
|
I: Iterator<Item = Result<T, Error>>
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
/// Extension trait for doing
|
|
||||||
///
|
|
||||||
/// ```ignore
|
|
||||||
/// Iterator<Item = Result<Option<T>, E>> -> Iterator<Item = Result<T, E>>
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
pub trait IterInnerOkOrElse<T, E, F>
|
|
||||||
where T: Sized,
|
|
||||||
E: Sized,
|
|
||||||
Self: Iterator<Item = Result<Option<T>, E>> + Sized,
|
|
||||||
F: Fn() -> E,
|
|
||||||
{
|
|
||||||
fn map_inner_ok_or_else(self, f: F) -> IterInnerOkOrElseImpl<Self, T, E, F>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct IterInnerOkOrElseImpl<I, T, E, F>(I, F)
|
|
||||||
where I: Iterator<Item = Result<Option<T>, E>> + Sized,
|
|
||||||
T: Sized,
|
|
||||||
E: Sized,
|
|
||||||
F: Fn() -> E;
|
|
||||||
|
|
||||||
impl<I, T, E, F> IterInnerOkOrElse<T, E, F> for I
|
|
||||||
where I: Iterator<Item = Result<Option<T>, E>> + Sized,
|
|
||||||
T: Sized,
|
|
||||||
E: Sized,
|
|
||||||
F: Fn() -> E,
|
|
||||||
{
|
|
||||||
fn map_inner_ok_or_else(self, f: F) -> IterInnerOkOrElseImpl<I, T, E, F> {
|
|
||||||
IterInnerOkOrElseImpl(self, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I, T, E, F> Iterator for IterInnerOkOrElseImpl<I, T, E, F>
|
|
||||||
where I: Iterator<Item = Result<Option<T>, E>> + Sized,
|
|
||||||
T: Sized,
|
|
||||||
E: Sized,
|
|
||||||
F: Fn() -> E,
|
|
||||||
{
|
|
||||||
type Item = Result<T, E>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.0.next().map(|e| e.and_then(|opt| opt.ok_or_else(|| (self.1)())))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ pub mod errors;
|
||||||
pub mod exit;
|
pub mod exit;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod iter;
|
pub mod iter;
|
||||||
pub mod result;
|
|
||||||
pub mod str;
|
pub mod str;
|
||||||
pub mod trace;
|
pub mod trace;
|
||||||
|
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2019 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
|
|
||||||
//
|
|
||||||
|
|
||||||
/// Extension trait for doing `Result<Option<T>, E> -> Result<T, E>`
|
|
||||||
pub trait ResultOptionExt<T, E, F>
|
|
||||||
where T: Sized,
|
|
||||||
E: Sized,
|
|
||||||
F: FnOnce() -> E
|
|
||||||
{
|
|
||||||
fn inner_ok_or_else(self, f: F) -> Result<T, E>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E, F> ResultOptionExt<T, E, F> for Result<Option<T>, E>
|
|
||||||
where T: Sized,
|
|
||||||
E: Sized,
|
|
||||||
F: FnOnce() -> E
|
|
||||||
{
|
|
||||||
fn inner_ok_or_else(self, f: F) -> Result<T, E> {
|
|
||||||
self.and_then(|opt| opt.ok_or_else(f))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue