Skip to content

Commit d4803bc

Browse files
Aaron1011carllerche
authored andcommitted
Use Sink trait from futures-sink-preview (#1244)
1 parent e07a03b commit d4803bc

File tree

8 files changed

+13
-77
lines changed

8 files changed

+13
-77
lines changed

tokio-futures/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ default = [
2424

2525
[dependencies]
2626
futures-core-preview = "0.3.0-alpha.17"
27+
futures-sink-preview = "0.3.0-alpha.17"

tokio-futures/src/sink.rs

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,3 @@
11
//! Sinks
22
3-
use core::marker::Unpin;
4-
use core::ops::DerefMut;
5-
use core::pin::Pin;
6-
use core::task::{Context, Poll};
7-
8-
/// Asynchronously send values
9-
pub trait Sink<T> {
10-
/// TODO: Dox
11-
type Error;
12-
13-
/// TODO: Dox
14-
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
15-
16-
/// TODO: Dox
17-
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>;
18-
19-
/// TODO: Dox
20-
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
21-
22-
/// TODO: Dox
23-
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
24-
}
25-
26-
impl<T, S: ?Sized + Sink<T> + Unpin> Sink<T> for &mut S {
27-
type Error = S::Error;
28-
29-
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
30-
Pin::new(&mut **self).poll_ready(cx)
31-
}
32-
33-
fn start_send(mut self: Pin<&mut Self>, item: T) -> Result<(), Self::Error> {
34-
Pin::new(&mut **self).start_send(item)
35-
}
36-
37-
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
38-
Pin::new(&mut **self).poll_flush(cx)
39-
}
40-
41-
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
42-
Pin::new(&mut **self).poll_close(cx)
43-
}
44-
}
45-
46-
impl<T, S> Sink<T> for Pin<S>
47-
where
48-
S: DerefMut + Unpin,
49-
S::Target: Sink<T>,
50-
{
51-
type Error = <S::Target as Sink<T>>::Error;
52-
53-
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
54-
Pin::get_mut(self).as_mut().poll_ready(cx)
55-
}
56-
57-
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error> {
58-
Pin::get_mut(self).as_mut().start_send(item)
59-
}
60-
61-
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
62-
Pin::get_mut(self).as_mut().poll_flush(cx)
63-
}
64-
65-
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
66-
Pin::get_mut(self).as_mut().poll_close(cx)
67-
}
68-
}
3+
pub use futures_sink::Sink;

tokio-sync/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ categories = ["asynchronous"]
2222
publish = false
2323

2424
[features]
25-
async-traits = ["async-sink", "futures-core-preview"]
25+
async-traits = ["tokio-futures", "futures-core-preview"]
2626

2727
[dependencies]
2828
async-util = { git = "https://github.com/tokio-rs/async" }
29-
async-sink = { git = "https://github.com/tokio-rs/async", optional = true }
29+
tokio-futures = { path = "../tokio-futures", optional = true }
3030
fnv = "1.0.6"
3131
futures-core-preview = { version = "0.3.0-alpha.17", optional = true }
3232

tokio-sync/src/mpsc/bounded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<T> Sender<T> {
214214
}
215215

216216
#[cfg(feature = "async-traits")]
217-
impl<T> async_sink::Sink<T> for Sender<T> {
217+
impl<T> tokio_futures::Sink<T> for Sender<T> {
218218
type Error = SendError;
219219

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

tokio-sync/src/mpsc/unbounded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<T> UnboundedSender<T> {
130130
}
131131

132132
#[cfg(feature = "async-traits")]
133-
impl<T> async_sink::Sink<T> for UnboundedSender<T> {
133+
impl<T> tokio_futures::Sink<T> for UnboundedSender<T> {
134134
type Error = UnboundedSendError;
135135

136136
fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {

tokio-sync/src/watch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<T> Sender<T> {
367367
}
368368

369369
#[cfg(feature = "async-traits")]
370-
impl<T> async_sink::Sink<T> for Sender<T> {
370+
impl<T> tokio_futures::Sink<T> for Sender<T> {
371371
type Error = error::SendError<T>;
372372

373373
fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {

tokio-sync/tests/mpsc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ async fn async_send_recv_with_buffer() {
5656
#[test]
5757
#[cfg(feature = "async-traits")]
5858
fn send_sink_recv_with_buffer() {
59-
use async_sink::Sink;
6059
use futures_core::Stream;
6160
use pin_utils::pin_mut;
61+
use tokio_futures::Sink;
6262

6363
let mut t1 = MockTask::new();
6464

@@ -169,9 +169,9 @@ async fn async_send_recv_unbounded() {
169169
#[test]
170170
#[cfg(feature = "async-traits")]
171171
fn sink_send_recv_unbounded() {
172-
use async_sink::Sink;
173172
use futures_core::Stream;
174173
use pin_utils::pin_mut;
174+
use tokio_futures::Sink;
175175

176176
let mut t1 = MockTask::new();
177177

tokio/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ publish = false
2626

2727
[features]
2828
default = [
29-
# "codec",
29+
"codec",
3030
# "fs",
3131
"io",
3232
"reactor",
@@ -38,7 +38,7 @@ default = [
3838
# "uds",
3939
]
4040

41-
#codec = ["io", "tokio-codec"]
41+
codec = ["io", "tokio-codec"]
4242
#fs = ["tokio-fs"]
4343
io = ["bytes", "tokio-io"]
4444
reactor = ["io", "tokio-reactor"]
@@ -65,14 +65,14 @@ udp = ["tokio-udp"]
6565
# Everything else is optional...
6666
bytes = { version = "0.4", optional = true }
6767
num_cpus = { version = "1.8.0", optional = true }
68-
#tokio-codec = { version = "0.2.0", optional = true, path = "../tokio-codec" }
68+
tokio-codec = { version = "0.2.0", optional = true, path = "../tokio-codec" }
6969
tokio-current-thread = { version = "0.2.0", optional = true, path = "../tokio-current-thread" }
7070
#tokio-fs = { version = "0.2.0", optional = true, path = "../tokio-fs" }
7171
tokio-io = { version = "0.2.0", optional = true, path = "../tokio-io" }
7272
tokio-executor = { version = "0.2.0", optional = true, path = "../tokio-executor" }
7373
tokio-macros = { version = "0.2.0", optional = true, path = "../tokio-macros" }
7474
tokio-reactor = { version = "0.2.0", optional = true, path = "../tokio-reactor" }
75-
tokio-sync = { version = "0.2.0", optional = true, path = "../tokio-sync" }
75+
tokio-sync = { version = "0.2.0", optional = true, path = "../tokio-sync", features = ["async-traits"] }
7676
#tokio-threadpool = { version = "0.2.0", optional = true, path = "../tokio-threadpool" }
7777
tokio-tcp = { version = "0.2.0", optional = true, path = "../tokio-tcp" }
7878
tokio-udp = { version = "0.2.0", optional = true, path = "../tokio-udp" }

0 commit comments

Comments
 (0)