Skip to content

Commit

Permalink
Rename Sink::SinkError to Sink::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jul 3, 2019
1 parent b385c4b commit c74f560
Show file tree
Hide file tree
Showing 56 changed files with 257 additions and 259 deletions.
30 changes: 15 additions & 15 deletions futures-channel/src/mpsc/sink_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ use futures_sink::Sink;
use std::pin::Pin;

impl<T> Sink<T> for Sender<T> {
type SinkError = SendError;
type Error = SendError;

fn poll_ready(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
(*self).poll_ready(cx)
}

fn start_send(
mut self: Pin<&mut Self>,
msg: T,
) -> Result<(), Self::SinkError> {
) -> Result<(), Self::Error> {
(*self).start_send(msg)
}

fn poll_flush(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
match (*self).poll_ready(cx) {
Poll::Ready(Err(ref e)) if e.is_disconnected() => {
// If the receiver disconnected, we consider the sink to be flushed.
Expand All @@ -36,71 +36,71 @@ impl<T> Sink<T> for Sender<T> {
fn poll_close(
mut self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
self.disconnect();
Poll::Ready(Ok(()))
}
}

impl<T> Sink<T> for UnboundedSender<T> {
type SinkError = SendError;
type Error = SendError;

fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
UnboundedSender::poll_ready(&*self, cx)
}

fn start_send(
mut self: Pin<&mut Self>,
msg: T,
) -> Result<(), Self::SinkError> {
) -> Result<(), Self::Error> {
UnboundedSender::start_send(&mut *self, msg)
}

fn poll_flush(
self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn poll_close(
mut self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
self.disconnect();
Poll::Ready(Ok(()))
}
}

impl<T> Sink<T> for &UnboundedSender<T> {
type SinkError = SendError;
type Error = SendError;

fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
UnboundedSender::poll_ready(*self, cx)
}

fn start_send(self: Pin<&mut Self>, msg: T) -> Result<(), Self::SinkError> {
fn start_send(self: Pin<&mut Self>, msg: T) -> Result<(), Self::Error> {
self.unbounded_send(msg)
.map_err(TrySendError::into_send_error)
}

fn poll_flush(
self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn poll_close(
self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Self::SinkError>> {
) -> Poll<Result<(), Self::Error>> {
self.close_channel();
Poll::Ready(Ok(()))
}
Expand Down
60 changes: 30 additions & 30 deletions futures-sink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use core::pin::Pin;
#[must_use = "sinks do nothing unless polled"]
pub trait Sink<Item> {
/// The type of value produced by the sink when an error occurs.
type SinkError;
type Error;

/// Attempts to prepare the `Sink` to receive a value.
///
Expand All @@ -63,7 +63,7 @@ pub trait Sink<Item> {
///
/// In most cases, if the sink encounters an error, the sink will
/// permanently be unable to receive items.
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>>;
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;

/// Begin the process of sending a value to the sink.
/// Each call to this function must be preceded by a successful call to
Expand All @@ -85,7 +85,7 @@ pub trait Sink<Item> {
/// In most cases, if the sink encounters an error, the sink will
/// permanently be unable to receive items.
fn start_send(self: Pin<&mut Self>, item: Item)
-> Result<(), Self::SinkError>;
-> Result<(), Self::Error>;

/// Flush any remaining output from this sink.
///
Expand All @@ -99,7 +99,7 @@ pub trait Sink<Item> {
///
/// In most cases, if the sink encounters an error, the sink will
/// permanently be unable to receive items.
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>>;
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;

/// Flush any remaining output and close this sink, if necessary.
///
Expand All @@ -112,25 +112,25 @@ pub trait Sink<Item> {
///
/// If this function encounters an error, the sink should be considered to
/// have failed permanently, and no more `Sink` methods should be called.
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>>;
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
}

impl<S: ?Sized + Sink<Item> + Unpin, Item> Sink<Item> for &mut S {
type SinkError = S::SinkError;
type Error = S::Error;

fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Pin::new(&mut **self).poll_ready(cx)
}

fn start_send(mut self: Pin<&mut Self>, item: Item) -> Result<(), Self::SinkError> {
fn start_send(mut self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error> {
Pin::new(&mut **self).start_send(item)
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Pin::new(&mut **self).poll_flush(cx)
}

fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Pin::new(&mut **self).poll_close(cx)
}
}
Expand All @@ -140,21 +140,21 @@ where
P: DerefMut + Unpin,
P::Target: Sink<Item>,
{
type SinkError = <P::Target as Sink<Item>>::SinkError;
type Error = <P::Target as Sink<Item>>::Error;

fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.get_mut().as_mut().poll_ready(cx)
}

fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::SinkError> {
fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error> {
self.get_mut().as_mut().start_send(item)
}

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.get_mut().as_mut().poll_flush(cx)
}

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.get_mut().as_mut().poll_close(cx)
}
}
Expand All @@ -165,65 +165,65 @@ mod if_alloc {
use futures_core::never::Never;

impl<T> Sink<T> for alloc::vec::Vec<T> {
type SinkError = Never;
type Error = Never;

fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::SinkError> {
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error> {
// TODO: impl<T> Unpin for Vec<T> {}
unsafe { self.get_unchecked_mut() }.push(item);
Ok(())
}

fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn poll_close(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_close(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
}

impl<T> Sink<T> for alloc::collections::VecDeque<T> {
type SinkError = Never;
type Error = Never;

fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::SinkError> {
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error> {
// TODO: impl<T> Unpin for Vec<T> {}
unsafe { self.get_unchecked_mut() }.push_back(item);
Ok(())
}

fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn poll_close(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_close(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
}

impl<S: ?Sized + Sink<Item> + Unpin, Item> Sink<Item> for alloc::boxed::Box<S> {
type SinkError = S::SinkError;
type Error = S::Error;

fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Pin::new(&mut **self).poll_ready(cx)
}

fn start_send(mut self: Pin<&mut Self>, item: Item) -> Result<(), Self::SinkError> {
fn start_send(mut self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error> {
Pin::new(&mut **self).start_send(item)
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Pin::new(&mut **self).poll_flush(cx)
}

fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Pin::new(&mut **self).poll_close(cx)
}
}
Expand Down
12 changes: 6 additions & 6 deletions futures-util/src/compat/compat01as03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub trait Sink01CompatExt: Sink01 {
/// Converts a futures 0.1
/// [`Sink<SinkItem = T, SinkError = E>`](futures_01::sink::Sink)
/// into a futures 0.3
/// [`Sink<SinkItem = T, SinkError = E>`](futures_sink::Sink).
/// [`Sink<T, Error = E>`](futures_sink::Sink).
///
/// ```
/// #![feature(async_await)]
Expand Down Expand Up @@ -222,12 +222,12 @@ impl<S, SinkItem> Sink03<SinkItem> for Compat01As03Sink<S, SinkItem>
where
S: Sink01<SinkItem = SinkItem>,
{
type SinkError = S::SinkError;
type Error = S::SinkError;

fn start_send(
mut self: Pin<&mut Self>,
item: SinkItem,
) -> Result<(), Self::SinkError> {
) -> Result<(), Self::Error> {
debug_assert!(self.buffer.is_none());
self.buffer = Some(item);
Ok(())
Expand All @@ -236,7 +236,7 @@ where
fn poll_ready(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> task03::Poll<Result<(), Self::SinkError>> {
) -> task03::Poll<Result<(), Self::Error>> {
match self.buffer.take() {
Some(item) => match self.in_notify(cx, |f| f.start_send(item))? {
AsyncSink01::Ready => task03::Poll::Ready(Ok(())),
Expand All @@ -252,7 +252,7 @@ where
fn poll_flush(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> task03::Poll<Result<(), Self::SinkError>> {
) -> task03::Poll<Result<(), Self::Error>> {
let item = self.buffer.take();
match self.in_notify(cx, |f| match item {
Some(i) => match f.start_send(i)? {
Expand All @@ -274,7 +274,7 @@ where
fn poll_close(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> task03::Poll<Result<(), Self::SinkError>> {
) -> task03::Poll<Result<(), Self::Error>> {
let item = self.buffer.take();
let close_started = self.close_started;

Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/compat/compat03as01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ where
T: Sink03<Item> + Unpin,
{
type SinkItem = Item;
type SinkError = T::SinkError;
type SinkError = T::Error;

fn start_send(
&mut self,
Expand Down
12 changes: 6 additions & 6 deletions futures-util/src/future/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ where
impl<A, B, Item> Sink<Item> for Either<A, B>
where
A: Sink<Item>,
B: Sink<Item, SinkError = A::SinkError>,
B: Sink<Item, Error = A::Error>,
{
type SinkError = A::SinkError;
type Error = A::Error;

fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
unsafe {
match self.get_unchecked_mut() {
Either::Left(x) => Pin::new_unchecked(x).poll_ready(cx),
Expand All @@ -124,7 +124,7 @@ where
}
}

fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::SinkError> {
fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error> {
unsafe {
match self.get_unchecked_mut() {
Either::Left(x) => Pin::new_unchecked(x).start_send(item),
Expand All @@ -133,7 +133,7 @@ where
}
}

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
unsafe {
match self.get_unchecked_mut() {
Either::Left(x) => Pin::new_unchecked(x).poll_flush(cx),
Expand All @@ -142,7 +142,7 @@ where
}
}

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::SinkError>> {
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
unsafe {
match self.get_unchecked_mut() {
Either::Left(x) => Pin::new_unchecked(x).poll_close(cx),
Expand Down
Loading

0 comments on commit c74f560

Please sign in to comment.