Skip to content

Commit c78dbdd

Browse files
Stjepan Glavinayoshuawuyts
authored andcommitted
Refactor extension_trait
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent e2db765 commit c78dbdd

File tree

13 files changed

+45
-58
lines changed

13 files changed

+45
-58
lines changed

src/fs/dir_builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::future::Future;
22

3+
use cfg_if::cfg_if;
4+
35
use crate::io;
46
use crate::path::Path;
57
use crate::task::blocking;

src/future/future.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension_trait! {
2929
3030
[`Waker`]: ../task/struct.Waker.html
3131
"#]
32-
pub trait Future [FutureExt: std::future::Future] {
32+
pub trait Future {
3333
#[doc = r#"
3434
The type of value produced on completion.
3535
"#]
@@ -101,4 +101,7 @@ extension_trait! {
101101
"#]
102102
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output>;
103103
}
104+
105+
pub trait FutureExt: std::future::Future {
106+
}
104107
}

src/io/buf_read/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension_trait! {
4444
https://docs.rs/futures-preview/0.3.0-alpha.17/futures/io/trait.AsyncBufRead.html
4545
[provided methods]: #provided-methods
4646
"#]
47-
pub trait BufRead [BufReadExt: futures_io::AsyncBufRead] {
47+
pub trait BufRead {
4848
#[doc = r#"
4949
Returns the contents of the internal buffer, filling it with more data from the
5050
inner reader if it is empty.
@@ -67,7 +67,9 @@ extension_trait! {
6767
should no longer be returned in calls to `read`.
6868
"#]
6969
fn consume(self: Pin<&mut Self>, amt: usize);
70+
}
7071

72+
pub trait BufReadExt: futures_io::AsyncBufRead {
7173
#[doc = r#"
7274
Reads all bytes into `buf` until the delimiter `byte` or EOF is reached.
7375

src/io/read/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension_trait! {
5050
[`poll_read`]: #tymethod.poll_read
5151
[`poll_read_vectored`]: #method.poll_read_vectored
5252
"#]
53-
pub trait Read [ReadExt: futures_io::AsyncRead] {
53+
pub trait Read {
5454
#[doc = r#"
5555
Attempt to read from the `AsyncRead` into `buf`.
5656
"#]
@@ -70,7 +70,9 @@ extension_trait! {
7070
) -> Poll<io::Result<usize>> {
7171
unreachable!("this impl only appears in the rendered docs")
7272
}
73+
}
7374

75+
pub trait ReadExt: futures_io::AsyncRead {
7476
#[doc = r#"
7577
Reads some bytes from the byte stream.
7678

src/io/seek.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension_trait! {
3333
https://docs.rs/futures-preview/0.3.0-alpha.17/futures/io/trait.AsyncSeek.html
3434
[provided methods]: #provided-methods
3535
"#]
36-
pub trait Seek [SeekExt: futures_io::AsyncSeek] {
36+
pub trait Seek {
3737
#[doc = r#"
3838
Attempt to seek to an offset, in bytes, in a stream.
3939
"#]
@@ -42,7 +42,9 @@ extension_trait! {
4242
cx: &mut Context<'_>,
4343
pos: SeekFrom,
4444
) -> Poll<io::Result<u64>>;
45+
}
4546

47+
pub trait SeekExt: futures_io::AsyncSeek {
4648
#[doc = r#"
4749
Seeks to a new position in a byte stream.
4850
@@ -70,7 +72,7 @@ extension_trait! {
7072
fn seek(
7173
&mut self,
7274
pos: SeekFrom,
73-
) -> impl Future<Output = io::Result<u64>> [SeekFuture<'_, Self>]
75+
) -> impl Future<Output = io::Result<u64>> + '_ [SeekFuture<'_, Self>]
7476
where
7577
Self: Unpin,
7678
{

src/io/write/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension_trait! {
4949
[`poll_flush`]: #tymethod.poll_flush
5050
[`poll_close`]: #tymethod.poll_close
5151
"#]
52-
pub trait Write [WriteExt: futures_io::AsyncWrite] {
52+
pub trait Write {
5353
#[doc = r#"
5454
Attempt to write bytes from `buf` into the object.
5555
"#]
@@ -80,7 +80,9 @@ extension_trait! {
8080
Attempt to close the object.
8181
"#]
8282
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>>;
83+
}
8384

85+
pub trait WriteExt: futures_io::AsyncWrite {
8486
#[doc = r#"
8587
Writes some bytes into the byte stream.
8688

src/stream/stream/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ cfg_if! {
9595

9696
use std::pin::Pin;
9797

98-
use std::future::Future;
98+
use crate::future::Future;
9999
use crate::stream::FromStream;
100100

101101
pub use merge::Merge;
@@ -122,7 +122,7 @@ extension_trait! {
122122
https://docs.rs/futures-preview/0.3.0-alpha.17/futures/stream/trait.Stream.html
123123
[provided methods]: #provided-methods
124124
"#]
125-
pub trait Stream [StreamExt: futures_core::stream::Stream] {
125+
pub trait Stream {
126126
#[doc = r#"
127127
The type of items yielded by this stream.
128128
"#]
@@ -180,7 +180,9 @@ extension_trait! {
180180
```
181181
"#]
182182
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
183+
}
183184

185+
pub trait StreamExt: futures_core::stream::Stream {
184186
#[doc = r#"
185187
Advances the stream and returns the next value.
186188

src/task/blocking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! A thread pool for running blocking functions asynchronously.
22
3-
use std::future::Future;
43
use std::sync::atomic::{AtomicU64, Ordering};
54
use std::thread;
65
use std::time::Duration;
76

87
use crossbeam_channel::{bounded, Receiver, Sender};
98
use lazy_static::lazy_static;
109

10+
use crate::future::Future;
1111
use crate::task::task::{JoinHandle, Tag};
1212
use crate::utils::abort_on_panic;
1313

src/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ cfg_if::cfg_if! {
8686
#[inline]
8787
pub fn blocking<F, R>(future: F) -> task::JoinHandle<R>
8888
where
89-
F: std::future::Future<Output = R> + Send + 'static,
89+
F: crate::future::Future<Output = R> + Send + 'static,
9090
R: Send + 'static,
9191
{
9292
blocking::spawn(future)

src/task/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::future::Future;
21
use std::iter;
32
use std::thread;
43

@@ -11,6 +10,7 @@ use super::task;
1110
use super::task_local;
1211
use super::worker;
1312
use super::{Builder, JoinHandle};
13+
use crate::future::Future;
1414
use crate::utils::abort_on_panic;
1515

1616
/// Spawns a task.

0 commit comments

Comments
 (0)