summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-04-12 10:58:11 +0000
committerGitHub <noreply@github.com>2023-04-12 10:58:11 +0000
commitb2d5ad298b84f69a4ce642a54a640e07c66ff9f0 (patch)
tree26a1fd00e2ea047785f5b0afc99ad12ed430f624
parent42cd8288976b30c404d35d4bcdc595d029a9ea1c (diff)
parent74fe7c936374ce04cb818f8a68915adadd8ae7f4 (diff)
Merge #27
27: Document unwrap r=matthiasbeyer a=johlrogge Co-authored-by: Joakim Ohlrogge <joakim.ohlrogge@gmail.com>
-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();
-}