use futures_core::future::Future;
use futures_core::stream::{Stream, TryStream};
use crate::future::Either;
#[cfg(feature = "compat")]
use crate::compat::CompatSink;
pub use futures_sink::Sink;
mod close;
pub use self::close::Close;
mod drain;
pub use self::drain::{drain, Drain};
mod fanout;
pub use self::fanout::Fanout;
mod flush;
pub use self::flush::Flush;
mod err_into;
pub use self::err_into::SinkErrInto;
mod map_err;
pub use self::map_err::SinkMapErr;
mod send;
pub use self::send::Send;
mod send_all;
pub use self::send_all::SendAll;
mod with;
pub use self::with::With;
mod with_flat_map;
pub use self::with_flat_map::WithFlatMap;
#[cfg(feature = "alloc")]
mod buffer;
#[cfg(feature = "alloc")]
pub use self::buffer::Buffer;
impl<T: ?Sized, Item> SinkExt<Item> for T where T: Sink<Item> {}
pub trait SinkExt<Item>: Sink<Item> {
fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
where F: FnMut(U) -> Fut,
Fut: Future<Output = Result<Item, E>>,
E: From<Self::Error>,
Self: Sized
{
With::new(self, f)
}
fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
where F: FnMut(U) -> St,
St: Stream<Item = Result<Item, Self::Error>>,
Self: Sized
{
WithFlatMap::new(self, f)
}
fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
where F: FnOnce(Self::Error) -> E,
Self: Sized,
{
SinkMapErr::new(self, f)
}
fn sink_err_into<E>(self) -> err_into::SinkErrInto<Self, Item, E>
where Self: Sized,
Self::Error: Into<E>,
{
SinkErrInto::new(self)
}
#[cfg(feature = "alloc")]
fn buffer(self, capacity: usize) -> Buffer<Self, Item>
where Self: Sized,
{
Buffer::new(self, capacity)
}
fn close(&mut self) -> Close<'_, Self, Item>
where Self: Unpin,
{
Close::new(self)
}
fn fanout<Si>(self, other: Si) -> Fanout<Self, Si>
where Self: Sized,
Item: Clone,
Si: Sink<Item, Error=Self::Error>
{
Fanout::new(self, other)
}
fn flush(&mut self) -> Flush<'_, Self, Item>
where Self: Unpin,
{
Flush::new(self)
}
fn send(&mut self, item: Item) -> Send<'_, Self, Item>
where Self: Unpin,
{
Send::new(self, item)
}
fn send_all<'a, St>(
&'a mut self,
stream: &'a mut St
) -> SendAll<'a, Self, St>
where St: TryStream<Ok = Item, Error = Self::Error> + Stream + Unpin + ?Sized,
Self: Unpin,
{
SendAll::new(self, stream)
}
fn left_sink<Si2>(self) -> Either<Self, Si2>
where Si2: Sink<Item, Error = Self::Error>,
Self: Sized
{
Either::Left(self)
}
fn right_sink<Si1>(self) -> Either<Si1, Self>
where Si1: Sink<Item, Error = Self::Error>,
Self: Sized
{
Either::Right(self)
}
#[cfg(feature = "compat")]
fn compat(self) -> CompatSink<Self, Item>
where Self: Sized + Unpin,
{
CompatSink::new(self)
}
}