Cleanup TryIgnore/TryExpect stream extensions related.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -5,9 +5,11 @@ mod option_stream;
|
|||||||
mod ready_eq_ext;
|
mod ready_eq_ext;
|
||||||
mod try_ext_ext;
|
mod try_ext_ext;
|
||||||
|
|
||||||
pub use bool_ext::{BoolExt, and, and4, and5, and6, and7, or};
|
pub use self::{
|
||||||
pub use ext_ext::ExtExt;
|
bool_ext::{BoolExt, and, and4, and5, and6, and7, or},
|
||||||
pub use option_ext::OptionExt;
|
ext_ext::ExtExt,
|
||||||
pub use option_stream::OptionStream;
|
option_ext::OptionExt,
|
||||||
pub use ready_eq_ext::ReadyEqExt;
|
option_stream::OptionStream,
|
||||||
pub use try_ext_ext::TryExtExt;
|
ready_eq_ext::ReadyEqExt,
|
||||||
|
try_ext_ext::TryExtExt,
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,25 +2,30 @@ use futures::{Stream, StreamExt, TryStream};
|
|||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
pub trait TryExpect<'a, Item> {
|
pub trait TryExpect<Item>
|
||||||
fn expect_ok(self) -> impl Stream<Item = Item> + Send + 'a;
|
where
|
||||||
|
Item: Send,
|
||||||
|
Self: Send + Sized,
|
||||||
|
{
|
||||||
|
fn expect_ok(self) -> impl Stream<Item = Item> + Send;
|
||||||
|
|
||||||
fn map_expect(self, msg: &'a str) -> impl Stream<Item = Item> + Send + 'a;
|
fn map_expect(self, msg: &str) -> impl Stream<Item = Item> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, Item> TryExpect<'a, Item> for T
|
impl<Item, S> TryExpect<Item> for S
|
||||||
where
|
where
|
||||||
T: Stream<Item = Result<Item>> + Send + TryStream + 'a,
|
S: Stream<Item = Result<Item>> + Send + TryStream,
|
||||||
Item: 'a,
|
Item: Send,
|
||||||
|
Self: Send + Sized,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn expect_ok(self: T) -> impl Stream<Item = Item> + Send + 'a {
|
fn expect_ok(self: S) -> impl Stream<Item = Item> + Send {
|
||||||
self.map_expect("stream expectation failure")
|
self.map_expect("stream expectation failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: move to impl MapExpect
|
//TODO: move to impl MapExpect
|
||||||
#[inline]
|
#[inline]
|
||||||
fn map_expect(self, msg: &'a str) -> impl Stream<Item = Item> + Send + 'a {
|
fn map_expect(self, msg: &str) -> impl Stream<Item = Item> + Send {
|
||||||
self.map(|res| res.expect(msg))
|
self.map(|res| res.expect(msg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,35 @@
|
|||||||
use futures::{Stream, StreamExt, TryStream, future::ready};
|
use futures::{Stream, StreamExt, TryStream, future::ready};
|
||||||
|
|
||||||
use crate::{Error, Result};
|
use crate::{Error, Result, utils::stream::TryExpect};
|
||||||
|
|
||||||
pub trait TryIgnore<'a, Item> {
|
pub trait TryIgnore<Item>
|
||||||
fn ignore_err(self) -> impl Stream<Item = Item> + Send + 'a;
|
where
|
||||||
|
Item: Send,
|
||||||
|
Self: Send + Sized,
|
||||||
|
{
|
||||||
|
fn ignore_err(self) -> impl Stream<Item = Item> + Send;
|
||||||
|
|
||||||
fn ignore_ok(self) -> impl Stream<Item = Error> + Send + 'a;
|
fn ignore_ok(self) -> impl Stream<Item = Error> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, Item> TryIgnore<'a, Item> for T
|
impl<Item, S> TryIgnore<Item> for S
|
||||||
where
|
where
|
||||||
T: Stream<Item = Result<Item>> + TryStream + Send + 'a,
|
S: Stream<Item = Result<Item>> + Send + TryStream + TryExpect<Item>,
|
||||||
Item: Send + 'a,
|
Item: Send,
|
||||||
|
Self: Send + Sized,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ignore_err(self: T) -> impl Stream<Item = Item> + Send + 'a {
|
fn ignore_err(self: S) -> impl Stream<Item = Item> + Send { self.expect_ok() }
|
||||||
use super::TryExpect;
|
|
||||||
|
|
||||||
self.expect_ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ignore_err(self: T) -> impl Stream<Item = Item> + Send + 'a {
|
fn ignore_err(self: S) -> impl Stream<Item = Item> + Send {
|
||||||
self.filter_map(|res| ready(res.ok()))
|
self.filter_map(|res| ready(res.ok()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ignore_ok(self: T) -> impl Stream<Item = Error> + Send + 'a {
|
fn ignore_ok(self: S) -> impl Stream<Item = Error> + Send {
|
||||||
self.filter_map(|res| ready(res.err()))
|
self.filter_map(|res| ready(res.err()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,20 +13,22 @@ mod try_tools;
|
|||||||
mod try_wideband;
|
mod try_wideband;
|
||||||
mod wideband;
|
mod wideband;
|
||||||
|
|
||||||
pub use band::{
|
pub use self::{
|
||||||
AMPLIFICATION_LIMIT, WIDTH_LIMIT, automatic_amplification, automatic_width,
|
band::{
|
||||||
set_amplification, set_width,
|
AMPLIFICATION_LIMIT, WIDTH_LIMIT, automatic_amplification, automatic_width,
|
||||||
|
set_amplification, set_width,
|
||||||
|
},
|
||||||
|
broadband::BroadbandExt,
|
||||||
|
cloned::Cloned,
|
||||||
|
expect::TryExpect,
|
||||||
|
ignore::TryIgnore,
|
||||||
|
iter_stream::IterStream,
|
||||||
|
ready::ReadyExt,
|
||||||
|
tools::Tools,
|
||||||
|
try_broadband::TryBroadbandExt,
|
||||||
|
try_parallel::TryParallelExt,
|
||||||
|
try_ready::TryReadyExt,
|
||||||
|
try_tools::TryTools,
|
||||||
|
try_wideband::TryWidebandExt,
|
||||||
|
wideband::WidebandExt,
|
||||||
};
|
};
|
||||||
pub use broadband::BroadbandExt;
|
|
||||||
pub use cloned::Cloned;
|
|
||||||
pub use expect::TryExpect;
|
|
||||||
pub use ignore::TryIgnore;
|
|
||||||
pub use iter_stream::IterStream;
|
|
||||||
pub use ready::ReadyExt;
|
|
||||||
pub use tools::Tools;
|
|
||||||
pub use try_broadband::TryBroadbandExt;
|
|
||||||
pub use try_parallel::TryParallelExt;
|
|
||||||
pub use try_ready::TryReadyExt;
|
|
||||||
pub use try_tools::TryTools;
|
|
||||||
pub use try_wideband::TryWidebandExt;
|
|
||||||
pub use wideband::WidebandExt;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user