diff --git a/src/core/utils/result/inspect_log.rs b/src/core/utils/result/inspect_log.rs index 577761c5..e9f32663 100644 --- a/src/core/utils/result/inspect_log.rs +++ b/src/core/utils/result/inspect_log.rs @@ -11,6 +11,7 @@ where { fn log_err(self, level: Level) -> Self; + #[inline] fn err_log(self) -> Self where Self: Sized, @@ -25,6 +26,7 @@ where { fn log_err_debug(self, level: Level) -> Self; + #[inline] fn err_debug_log(self) -> Self where Self: Sized, diff --git a/src/core/utils/stream/ready.rs b/src/core/utils/stream/ready.rs index c16d1246..f4eec7d1 100644 --- a/src/core/utils/stream/ready.rs +++ b/src/core/utils/stream/ready.rs @@ -32,6 +32,11 @@ where where F: Fn(T, Item) -> T; + fn ready_fold_default(self, f: F) -> Fold, T, impl FnMut(T, Item) -> Ready> + where + F: Fn(T, Item) -> T, + T: Default; + fn ready_for_each(self, f: F) -> ForEach, impl FnMut(Item) -> Ready<()>> where F: FnMut(Item); @@ -93,6 +98,15 @@ where self.fold(init, move |a, t| ready(f(a, t))) } + #[inline] + fn ready_fold_default(self, f: F) -> Fold, T, impl FnMut(T, Item) -> Ready> + where + F: Fn(T, Item) -> T, + T: Default, + { + self.ready_fold(T::default(), f) + } + #[inline] #[allow(clippy::unit_arg)] fn ready_for_each(self, mut f: F) -> ForEach, impl FnMut(Item) -> Ready<()>> @@ -120,6 +134,7 @@ where self.scan(init, move |s, t| ready(f(s, t))) } + #[inline] fn ready_scan_each( self, init: T, f: F, ) -> Scan>, impl FnMut(&mut T, Item) -> Ready>> diff --git a/src/core/utils/stream/try_ready.rs b/src/core/utils/stream/try_ready.rs index 3fbcbc45..0daed26e 100644 --- a/src/core/utils/stream/try_ready.rs +++ b/src/core/utils/stream/try_ready.rs @@ -3,7 +3,7 @@ use futures::{ future::{ready, Ready}, - stream::{AndThen, TryForEach, TryStream, TryStreamExt}, + stream::{AndThen, TryFold, TryForEach, TryStream, TryStreamExt}, }; use crate::Result; @@ -25,6 +25,19 @@ where ) -> TryForEach>, impl FnMut(S::Ok) -> Ready>> where F: FnMut(S::Ok) -> Result<(), E>; + + fn ready_try_fold( + self, init: U, f: F, + ) -> TryFold>, U, impl FnMut(U, S::Ok) -> Ready>> + where + F: Fn(U, S::Ok) -> Result; + + fn ready_try_fold_default( + self, f: F, + ) -> TryFold>, U, impl FnMut(U, S::Ok) -> Ready>> + where + F: Fn(U, S::Ok) -> Result, + U: Default; } impl TryReadyExt for S @@ -49,4 +62,25 @@ where { self.try_for_each(move |t| ready(f(t))) } + + #[inline] + fn ready_try_fold( + self, init: U, f: F, + ) -> TryFold>, U, impl FnMut(U, S::Ok) -> Ready>> + where + F: Fn(U, S::Ok) -> Result, + { + self.try_fold(init, move |a, t| ready(f(a, t))) + } + + #[inline] + fn ready_try_fold_default( + self, f: F, + ) -> TryFold>, U, impl FnMut(U, S::Ok) -> Ready>> + where + F: Fn(U, S::Ok) -> Result, + U: Default, + { + self.ready_try_fold(U::default(), f) + } }