forked from tokio-rs/tokio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Sink trait from futures-sink-preview (tokio-rs#1244)
- Loading branch information
1 parent
e07a03b
commit d4803bc
Showing
8 changed files
with
13 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ default = [ | |
|
||
[dependencies] | ||
futures-core-preview = "0.3.0-alpha.17" | ||
futures-sink-preview = "0.3.0-alpha.17" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,3 @@ | ||
//! Sinks | ||
use core::marker::Unpin; | ||
use core::ops::DerefMut; | ||
use core::pin::Pin; | ||
use core::task::{Context, Poll}; | ||
|
||
/// Asynchronously send values | ||
pub trait Sink<T> { | ||
/// TODO: Dox | ||
type Error; | ||
|
||
/// TODO: Dox | ||
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>; | ||
|
||
/// TODO: Dox | ||
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>; | ||
|
||
/// TODO: Dox | ||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>; | ||
|
||
/// TODO: Dox | ||
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>; | ||
} | ||
|
||
impl<T, S: ?Sized + Sink<T> + Unpin> Sink<T> for &mut S { | ||
type Error = S::Error; | ||
|
||
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: T) -> Result<(), Self::Error> { | ||
Pin::new(&mut **self).start_send(item) | ||
} | ||
|
||
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::Error>> { | ||
Pin::new(&mut **self).poll_close(cx) | ||
} | ||
} | ||
|
||
impl<T, S> Sink<T> for Pin<S> | ||
where | ||
S: DerefMut + Unpin, | ||
S::Target: Sink<T>, | ||
{ | ||
type Error = <S::Target as Sink<T>>::Error; | ||
|
||
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
Pin::get_mut(self).as_mut().poll_ready(cx) | ||
} | ||
|
||
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error> { | ||
Pin::get_mut(self).as_mut().start_send(item) | ||
} | ||
|
||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
Pin::get_mut(self).as_mut().poll_flush(cx) | ||
} | ||
|
||
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
Pin::get_mut(self).as_mut().poll_close(cx) | ||
} | ||
} | ||
pub use futures_sink::Sink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters