#![no_std]
#![deny(missing_docs, missing_debug_implementations)]
#![doc(html_root_url = "https://docs.rs/futures-sink/0.2.1")]
#[cfg(feature = "std")]
extern crate std;
extern crate futures_core;
#[cfg(feature = "std")]
extern crate futures_channel;
macro_rules! if_std {
($($i:item)*) => ($(
#[cfg(feature = "std")]
$i
)*)
}
use futures_core::{Poll, task};
#[cfg(feature = "either")]
extern crate either;
#[cfg(feature = "either")]
use either::Either;
#[cfg(feature = "either")]
impl<A, B> Sink for Either<A, B>
where A: Sink,
B: Sink<SinkItem=<A as Sink>::SinkItem,
SinkError=<A as Sink>::SinkError>
{
type SinkItem = <A as Sink>::SinkItem;
type SinkError = <A as Sink>::SinkError;
fn poll_ready(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
match *self {
Either::Left(ref mut x) => x.poll_ready(cx),
Either::Right(ref mut x) => x.poll_ready(cx),
}
}
fn start_send(&mut self, item: Self::SinkItem) -> Result<(), Self::SinkError> {
match *self {
Either::Left(ref mut x) => x.start_send(item),
Either::Right(ref mut x) => x.start_send(item),
}
}
fn poll_flush(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
match *self {
Either::Left(ref mut x) => x.poll_flush(cx),
Either::Right(ref mut x) => x.poll_flush(cx),
}
}
fn poll_close(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
match *self {
Either::Left(ref mut x) => x.poll_close(cx),
Either::Right(ref mut x) => x.poll_close(cx),
}
}
}
if_std! {
mod channel_impls;
use futures_core::Async;
use futures_core::never::Never;
impl<T> Sink for ::std::vec::Vec<T> {
type SinkItem = T;
type SinkError = Never;
fn poll_ready(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> {
Ok(Async::Ready(()))
}
fn start_send(&mut self, item: Self::SinkItem) -> Result<(), Self::SinkError> {
self.push(item);
Ok(())
}
fn poll_flush(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> {
Ok(Async::Ready(()))
}
fn poll_close(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> {
Ok(Async::Ready(()))
}
}
impl<T> Sink for ::std::collections::VecDeque<T> {
type SinkItem = T;
type SinkError = Never;
fn poll_ready(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> {
Ok(Async::Ready(()))
}
fn start_send(&mut self, item: Self::SinkItem) -> Result<(), Self::SinkError> {
self.push_back(item);
Ok(())
}
fn poll_flush(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> {
Ok(Async::Ready(()))
}
fn poll_close(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> {
Ok(Async::Ready(()))
}
}
impl<S: ?Sized + Sink> Sink for ::std::boxed::Box<S> {
type SinkItem = S::SinkItem;
type SinkError = S::SinkError;
fn poll_ready(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
(**self).poll_ready(cx)
}
fn start_send(&mut self, item: Self::SinkItem) -> Result<(), Self::SinkError> {
(**self).start_send(item)
}
fn poll_flush(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
(**self).poll_flush(cx)
}
fn poll_close(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
(**self).poll_close(cx)
}
}
}
pub trait Sink {
type SinkItem;
type SinkError;
fn poll_ready(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError>;
fn start_send(&mut self, item: Self::SinkItem)
-> Result<(), Self::SinkError>;
fn poll_flush(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError>;
fn poll_close(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError>;
}
impl<'a, S: ?Sized + Sink> Sink for &'a mut S {
type SinkItem = S::SinkItem;
type SinkError = S::SinkError;
fn poll_ready(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
(**self).poll_ready(cx)
}
fn start_send(&mut self, item: Self::SinkItem) -> Result<(), Self::SinkError> {
(**self).start_send(item)
}
fn poll_flush(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
(**self).poll_flush(cx)
}
fn poll_close(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> {
(**self).poll_close(cx)
}
}