summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/unwrap.rs40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/unwrap.rs b/src/unwrap.rs
index 93a7314..d219a80 100644
--- a/src/unwrap.rs
+++ b/src/unwrap.rs
@@ -45,6 +45,35 @@ where
I: Iterator<Item = Result<O, E>>,
F: FnMut(E) -> Option<O>,
{
+ /// Unwraps all results
+ ///
+ /// Errors can be ignored:
+ /// ```
+ /// use resiter::unwrap::UnwrapWithExt;
+ /// use std::str::FromStr;
+ ///
+ /// let unwrapped: Vec<usize> = ["1", "2", "a", "b", "5"]
+ /// .iter()
+ /// .map(|e| usize::from_str(e))
+ /// .unwrap_with(|_| None) // ignore errors
+ /// .collect();
+ ///
+ /// assert_eq!(unwrapped, vec![1, 2, 5],);
+ /// ```
+ ///
+ /// Or simply converted:
+ /// ```
+ /// use resiter::unwrap::UnwrapWithExt;
+ /// use std::str::FromStr;
+ ///
+ /// let unwrapped: Vec<usize> = ["1", "2", "a", "b", "5"]
+ /// .iter()
+ /// .map(|e| usize::from_str(e))
+ /// .unwrap_with(|_| Some(8)) // convert errors
+ /// .collect();
+ ///
+ /// assert_eq!(unwrapped, vec![1, 2, 8, 8, 5],);
+ /// ```
fn unwrap_with(self, _: F) -> UnwrapWith<I, O, E, F>;
}
@@ -57,14 +86,3 @@ where
UnwrapWith(self, f)
}
}
-
-#[test]
-fn test_compile_1() {
- use std::str::FromStr;
-
- let _: Vec<usize> = ["1", "2", "3", "4", "5"]
- .iter()
- .map(|e| usize::from_str(e))
- .unwrap_with(|_| None) // ignore errors
- .collect();
-}