use crate::future::{Deadline, IntoFuture};
use futures_core::Stream;
use super::{Buffer, Debounce, Delay, IntoStream, Sample, Throttle, Timeout};
pub trait StreamExt: Stream {
fn sample<I>(self, interval: I) -> Sample<Self, I::IntoStream>
where
Self: Sized,
I: IntoStream,
{
Sample::new(self, interval.into_stream())
}
fn buffer<I>(self, interval: I) -> Buffer<Self, I::IntoStream>
where
Self: Sized,
I: IntoStream,
{
Buffer::new(self, interval.into_stream())
}
fn debounce<D>(self, deadline: D) -> Debounce<Self, D::IntoFuture>
where
Self: Sized,
D: IntoFuture,
D::IntoFuture: Deadline,
{
Debounce::new(self, deadline.into_future())
}
fn delay<D>(self, deadline: D) -> Delay<Self, D::IntoFuture>
where
Self: Sized,
D: IntoFuture,
{
Delay::new(self, deadline.into_future())
}
fn throttle<I>(self, interval: I) -> Throttle<Self, I::IntoStream>
where
Self: Sized,
I: IntoStream,
{
Throttle::new(self, interval.into_stream())
}
fn timeout<D>(self, deadline: D) -> Timeout<Self, D::IntoFuture>
where
Self: Sized,
D: IntoFuture,
D::IntoFuture: Deadline,
{
Timeout::new(self, deadline.into_future())
}
}
impl<S> StreamExt for S where S: Stream {}