diff options
author | Matthias Beyer <matthias.beyer@ifm.com> | 2022-05-19 12:25:39 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-05-23 12:17:59 +0200 |
commit | 62718fcc07e07fd49f3d42a05b4b132d76d2dd27 (patch) | |
tree | caa4beb27725901f57ed4121ac28b37465bf0439 | |
parent | 176e51960ee45d63901364257476a1cb9892b485 (diff) |
Add SendAllResult::into_result()
It was discovered that the Into<_> implementation for the SendAllResult
type was not as nice as we thought: Type annotations were needed, which
resulted in less function-chaining in the using code.
Therefore this patch adds a SendAllResult::into_result() function, which
can easily be used in a function chain.
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r-- | crates/core/tedge_lib/src/iter/result.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/core/tedge_lib/src/iter/result.rs b/crates/core/tedge_lib/src/iter/result.rs index 984ac9b9..879ac8de 100644 --- a/crates/core/tedge_lib/src/iter/result.rs +++ b/crates/core/tedge_lib/src/iter/result.rs @@ -108,6 +108,14 @@ where pub fn into_errs(self) -> Vec<M> { self.errs } + + pub fn into_result(self) -> Result<Vec<tedge_api::address::ReplyReceiverFor<M>>, Vec<M>> { + if !self.errs().is_empty() { + Ok(self.into_oks()) + } else { + Err(self.into_errs()) + } + } } impl<M> Into<Result<Vec<tedge_api::address::ReplyReceiverFor<M>>, Vec<M>>> for SendAllResult<M> |