summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-04-09 10:53:34 +0000
committerGitHub <noreply@github.com>2023-04-09 10:53:34 +0000
commit0daf6bdd9c973013ed382e093cb0f294c152c843 (patch)
treebc7fdcb8dad778cfc9d7a0e0a8fe9a3c0cdf1c49
parent2b6c0c370c80164e4f321c590eadfd0a044cc945 (diff)
parent84939f5bb6168f3b5973d69d9c3f825ed03d88b6 (diff)
Merge #6
6: Add documentation for extension traits r=matthiasbeyer a=matthiasbeyer Co-authored-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/lib.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b5ccfab..1ea06f7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,11 +1,13 @@
//! This crate adds the missing Result::inspect function via an extension trait
//!
+/// Extension trait for adding Result::inspect
pub trait ResultInspect<F, T>
where
F: FnOnce(&T),
T: Sized,
{
+ /// Call `f` on T if the Result is a Ok(T), or do nothing if the Result is an Err
fn inspect(self, f: F) -> Self;
}
@@ -22,6 +24,7 @@ where
F: FnOnce(&T),
T: Sized,
{
+ /// Call `f` on T if the Result is a Ok(T), or do nothing if the Result is an Err
fn inspect(self, f: F) -> Self {
if let Ok(o) = self.as_ref() {
(f)(o);
@@ -43,11 +46,13 @@ where
}
}
+/// Extension trait for adding Result::inspect_err
pub trait ResultInspectErr<F, E>
where
F: FnOnce(&E),
E: Sized,
{
+ /// Call `f` on T if the Result is a Err(E), or do nothing if the Result is an Ok
fn inspect_err(self, f: F) -> Self;
}
@@ -64,6 +69,7 @@ where
F: FnOnce(&E),
E: Sized,
{
+ /// Call `f` on T if the Result is a Err(E), or do nothing if the Result is an Ok
fn inspect_err(self, f: F) -> Self {
if let Err(e) = self.as_ref() {
(f)(e);