diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index e20f8bac..a244c285 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -22,7 +22,6 @@ cfg_unstable_default! { pub use core::future::Future as Future; -extension_trait! { #[doc = r#" Extension methods for [`Future`]. @@ -45,7 +44,7 @@ extension_trait! { /// ``` #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn delay(self, dur: Duration) -> [DelayFuture] + fn delay(self, dur: Duration) -> DelayFuture where Self: Sized, { @@ -70,7 +69,7 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn flatten( self, - ) -> [FlattenFuture::Future>] + ) -> FlattenFuture::Future> where Self: Sized, ::Output: IntoFuture, @@ -112,7 +111,7 @@ extension_trait! { fn race( self, other: F, - ) -> [Race] + ) -> Race where Self: std::future::Future + Sized, F: std::future::Future::Output>, @@ -158,7 +157,7 @@ extension_trait! { fn try_race( self, other: F - ) -> [TryRace] + ) -> TryRace where Self: std::future::Future> + Sized, F: std::future::Future::Output>, @@ -195,7 +194,7 @@ extension_trait! { fn join( self, other: F - ) -> [Join] + ) -> Join where Self: std::future::Future + Sized, F: std::future::Future, @@ -242,7 +241,7 @@ extension_trait! { fn try_join( self, other: F - ) -> [TryJoin] + ) -> TryJoin where Self: std::future::Future> + Sized, F: std::future::Future>, @@ -278,13 +277,12 @@ extension_trait! { "#] #[cfg(any(all(feature = "default", feature = "unstable"), feature = "docs"))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn timeout(self, dur: Duration) -> [TimeoutFuture] + fn timeout(self, dur: Duration) -> TimeoutFuture where Self: Sized { TimeoutFuture::new(self, dur) } } -} impl FutureExt for T {} diff --git a/src/io/buf_read/mod.rs b/src/io/buf_read/mod.rs index 8f248e2b..f8bffaf3 100644 --- a/src/io/buf_read/mod.rs +++ b/src/io/buf_read/mod.rs @@ -17,7 +17,6 @@ use crate::task::{Context, Poll}; pub use futures_io::AsyncBufRead as BufRead; -extension_trait! { #[doc = r#" Extension methods for [`BufRead`]. @@ -78,7 +77,7 @@ extension_trait! { &'a mut self, byte: u8, buf: &'a mut Vec, - ) -> [ReadUntilFuture<'a, Self>] + ) -> ReadUntilFuture<'a, Self> where Self: Unpin, { @@ -131,7 +130,7 @@ extension_trait! { fn read_line<'a>( &'a mut self, buf: &'a mut String, - ) -> [ReadLineFuture<'a, Self>] + ) -> ReadLineFuture<'a, Self> where Self: Unpin, { @@ -237,7 +236,6 @@ extension_trait! { } } } -} impl BufReadExt for T {} diff --git a/src/io/read/mod.rs b/src/io/read/mod.rs index f96b8154..0109a3ac 100644 --- a/src/io/read/mod.rs +++ b/src/io/read/mod.rs @@ -23,7 +23,6 @@ pub use take::Take; pub use futures_io::AsyncRead as Read; -extension_trait! { #[doc = r#" Extension methods for [`Read`]. @@ -64,7 +63,7 @@ extension_trait! { fn read<'a>( &'a mut self, buf: &'a mut [u8], - ) -> [ReadFuture<'a, Self>] + ) -> ReadFuture<'a, Self> where Self: Unpin { @@ -86,7 +85,7 @@ extension_trait! { fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>], - ) -> [ReadVectoredFuture<'a, Self>] + ) -> ReadVectoredFuture<'a, Self> where Self: Unpin, { @@ -123,7 +122,7 @@ extension_trait! { fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec, - ) -> [ReadToEndFuture<'a, Self>] + ) -> ReadToEndFuture<'a, Self> where Self: Unpin, { @@ -162,7 +161,7 @@ extension_trait! { fn read_to_string<'a>( &'a mut self, buf: &'a mut String, - ) -> [ReadToStringFuture<'a, Self>] + ) -> ReadToStringFuture<'a, Self> where Self: Unpin, { @@ -217,7 +216,7 @@ extension_trait! { fn read_exact<'a>( &'a mut self, buf: &'a mut [u8], - ) -> [ReadExactFuture<'a, Self>] + ) -> ReadExactFuture<'a, Self> where Self: Unpin, { @@ -373,7 +372,6 @@ extension_trait! { Chain { first: self, second: next, done_first: false } } } -} impl ReadExt for T {} diff --git a/src/io/seek/mod.rs b/src/io/seek/mod.rs index af7cafcf..f2b60932 100644 --- a/src/io/seek/mod.rs +++ b/src/io/seek/mod.rs @@ -6,7 +6,6 @@ use crate::io::SeekFrom; pub use futures_io::AsyncSeek as Seek; -extension_trait! { #[doc = r#" Extension methods for [`Seek`]. @@ -40,13 +39,12 @@ extension_trait! { fn seek( &mut self, pos: SeekFrom, - ) -> [SeekFuture<'_, Self>] + ) -> SeekFuture<'_, Self> where Self: Unpin, { SeekFuture { seeker: self, pos } } } -} impl SeekExt for T {} diff --git a/src/io/write/mod.rs b/src/io/write/mod.rs index b18d80f0..d73c40d8 100644 --- a/src/io/write/mod.rs +++ b/src/io/write/mod.rs @@ -14,7 +14,6 @@ use crate::io::{self, IoSlice}; pub use futures_io::AsyncWrite as Write; -extension_trait! { #[doc = r#" Extension methods for [`Write`]. @@ -49,7 +48,7 @@ extension_trait! { fn write<'a>( &'a mut self, buf: &'a [u8], - ) -> [WriteFuture<'a, Self>] + ) -> WriteFuture<'a, Self> where Self: Unpin, { @@ -75,7 +74,7 @@ extension_trait! { # Ok(()) }) } ``` "#] - fn flush(&mut self) -> [FlushFuture<'_, Self>] + fn flush(&mut self) -> FlushFuture<'_, Self> where Self: Unpin, { @@ -97,7 +96,7 @@ extension_trait! { fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], - ) -> [WriteVectoredFuture<'a, Self>] + ) -> WriteVectoredFuture<'a, Self> where Self: Unpin, { @@ -133,7 +132,7 @@ extension_trait! { fn write_all<'a>( &'a mut self, buf: &'a [u8], - ) -> [WriteAllFuture<'a, Self>] + ) -> WriteAllFuture<'a, Self> where Self: Unpin, { @@ -170,7 +169,7 @@ extension_trait! { fn write_fmt<'a>( &'a mut self, fmt: std::fmt::Arguments<'_>, - ) -> [WriteFmtFuture<'a, Self>] + ) -> WriteFmtFuture<'a, Self> where Self: Unpin, { @@ -184,6 +183,5 @@ extension_trait! { WriteFmtFuture { writer: self, res: Some(res), buffer: None, amt: 0 } } } -} impl WriteExt for T {} diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index 0ead0800..25aadfac 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -145,7 +145,6 @@ cfg_unstable! { pub use futures_core::stream::Stream as Stream; -extension_trait! { #[doc = r#" Extension methods for [`Stream`]. @@ -177,7 +176,7 @@ extension_trait! { # }) } ``` "#] - fn next(&mut self) -> [NextFuture<'_, Self>] + fn next(&mut self) -> NextFuture<'_, Self> where Self: Unpin, { @@ -629,7 +628,7 @@ extension_trait! { "#] fn last( self, - ) -> [LastFuture] + ) -> LastFuture where Self: Sized, { @@ -839,7 +838,7 @@ extension_trait! { fn min_by_key( self, key_by: F, - ) -> [MinByKeyFuture] + ) -> MinByKeyFuture where Self: Sized, B: Ord, @@ -875,7 +874,7 @@ extension_trait! { fn max_by_key( self, key_by: F, - ) -> [MaxByKeyFuture] + ) -> MaxByKeyFuture where Self: Sized, B: Ord, @@ -914,7 +913,7 @@ extension_trait! { fn min_by( self, compare: F, - ) -> [MinByFuture] + ) -> MinByFuture where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering, @@ -947,7 +946,7 @@ extension_trait! { "#] fn max( self, - ) -> [MaxFuture] + ) -> MaxFuture where Self: Sized, Self::Item: Ord, @@ -980,7 +979,7 @@ extension_trait! { "#] fn min( self, - ) -> [MinFuture] + ) -> MinFuture where Self: Sized, Self::Item: Ord, @@ -1018,7 +1017,7 @@ extension_trait! { fn max_by( self, compare: F, - ) -> [MaxByFuture] + ) -> MaxByFuture where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering, @@ -1082,7 +1081,7 @@ extension_trait! { fn nth( &mut self, n: usize, - ) -> [NthFuture<'_, Self>] + ) -> NthFuture<'_, Self> where Self: Unpin + Sized, { @@ -1138,7 +1137,7 @@ extension_trait! { fn all( &mut self, f: F, - ) -> [AllFuture<'_, Self, F, Self::Item>] + ) -> AllFuture<'_, Self, F, Self::Item> where Self: Unpin + Sized, F: FnMut(Self::Item) -> bool, @@ -1187,7 +1186,7 @@ extension_trait! { fn find

( &mut self, p: P, - ) -> [FindFuture<'_, Self, P>] + ) -> FindFuture<'_, Self, P> where Self: Unpin + Sized, P: FnMut(&Self::Item) -> bool, @@ -1215,7 +1214,7 @@ extension_trait! { fn find_map( &mut self, f: F, - ) -> [FindMapFuture<'_, Self, F>] + ) -> FindMapFuture<'_, Self, F> where Self: Unpin + Sized, F: FnMut(Self::Item) -> Option, @@ -1249,7 +1248,7 @@ extension_trait! { self, init: B, f: F, - ) -> [FoldFuture] + ) -> FoldFuture where Self: Sized, F: FnMut(B, Self::Item) -> B, @@ -1286,7 +1285,7 @@ extension_trait! { fn partition( self, f: F, - ) -> [PartitionFuture] + ) -> PartitionFuture where Self: Sized, F: FnMut(&Self::Item) -> bool, @@ -1322,7 +1321,7 @@ extension_trait! { fn for_each( self, f: F, - ) -> [ForEachFuture] + ) -> ForEachFuture where Self: Sized, F: FnMut(Self::Item), @@ -1378,7 +1377,7 @@ extension_trait! { fn any( &mut self, f: F, - ) -> [AnyFuture<'_, Self, F, Self::Item>] + ) -> AnyFuture<'_, Self, F, Self::Item> where Self: Unpin + Sized, F: FnMut(Self::Item) -> bool, @@ -1614,7 +1613,7 @@ extension_trait! { &mut self, init: T, f: F, - ) -> [TryFoldFuture<'_, Self, F, T>] + ) -> TryFoldFuture<'_, Self, F, T> where Self: Unpin + Sized, F: FnMut(B, Self::Item) -> Result, @@ -1659,7 +1658,7 @@ extension_trait! { fn try_for_each( &mut self, f: F, - ) -> [TryForEachFuture<'_, Self, F>] + ) -> TryForEachFuture<'_, Self, F> where Self: Unpin + Sized, F: FnMut(Self::Item) -> Result<(), E>, @@ -1741,7 +1740,7 @@ extension_trait! { "#] #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn unzip(self) -> [UnzipFuture] + fn unzip(self) -> UnzipFuture where FromA: Default + Extend, FromB: Default + Extend, @@ -1805,7 +1804,7 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn collect<'a, B>( self, - ) -> [Pin + 'a + Send>>] + ) -> Pin + 'a + Send>> where Self: Sized + 'a + Send, B: FromStream, @@ -1879,7 +1878,7 @@ extension_trait! { fn partial_cmp( self, other: S - ) -> [PartialCmpFuture] + ) -> PartialCmpFuture where Self: Sized + Stream, S: Stream, @@ -1919,7 +1918,7 @@ extension_trait! { fn position

( &mut self, predicate: P, - ) -> [PositionFuture<'_, Self, P>] + ) -> PositionFuture<'_, Self, P> where Self: Unpin + Sized, P: FnMut(Self::Item) -> bool, @@ -1957,7 +1956,7 @@ extension_trait! { fn cmp( self, other: S - ) -> [CmpFuture] + ) -> CmpFuture where Self: Sized + Stream, S: Stream, @@ -1988,7 +1987,7 @@ extension_trait! { "#] #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn count(self) -> [CountFuture] + fn count(self) -> CountFuture where Self: Sized, { @@ -2023,7 +2022,7 @@ extension_trait! { fn ne( self, other: S - ) -> [NeFuture] + ) -> NeFuture where Self: Sized, S: Sized + Stream, @@ -2060,7 +2059,7 @@ extension_trait! { fn ge( self, other: S - ) -> [GeFuture] + ) -> GeFuture where Self: Sized + Stream, S: Stream, @@ -2097,7 +2096,7 @@ extension_trait! { fn eq( self, other: S - ) -> [EqFuture] + ) -> EqFuture where Self: Sized + Stream, S: Sized + Stream, @@ -2134,7 +2133,7 @@ extension_trait! { fn gt( self, other: S - ) -> [GtFuture] + ) -> GtFuture where Self: Sized + Stream, S: Stream, @@ -2171,7 +2170,7 @@ extension_trait! { fn le( self, other: S - ) -> [LeFuture] + ) -> LeFuture where Self: Sized + Stream, S: Stream, @@ -2208,7 +2207,7 @@ extension_trait! { fn lt( self, other: S - ) -> [LtFuture] + ) -> LtFuture where Self: Sized + Stream, S: Stream, @@ -2252,7 +2251,7 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn sum<'a, S>( self, - ) -> [Pin + 'a>>] + ) -> Pin + 'a>> where Self: Sized + Stream + 'a, S: Sum, @@ -2298,7 +2297,7 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn product<'a, P>( self, - ) -> [Pin + 'a>>] + ) -> Pin + 'a>> where Self: Sized + Stream + 'a, P: Product, @@ -2306,7 +2305,6 @@ extension_trait! { Product::product(self) } } -} impl StreamExt for T {} diff --git a/src/utils.rs b/src/utils.rs index 96f24fd2..d1b49727 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -233,41 +233,3 @@ macro_rules! cfg_default { )* } } - -/// Defines an extension trait for a base trait. -/// -/// In generated docs, the base trait will contain methods from the extension trait. In actual -/// code, the base trait will be re-exported and the extension trait will be hidden. We then -/// re-export the extension trait from the prelude. -/// -/// Inside invocations of this macro, we write a definitions that looks similar to the final -/// rendered docs, and the macro then generates all the boilerplate for us. -#[allow(unused_macros)] -#[doc(hidden)] -macro_rules! extension_trait { - ( - #[doc = $doc_ext:tt] - pub trait $ext:ident: $name:ident { - $($body_ext:tt)* - } - ) => { - // The extension trait that adds methods to any type implementing the base trait. - #[doc = $doc_ext] - pub trait $ext: $name { - extension_trait!(@ext [$($body_ext)*] -> []); - } - }; - - // Parse the return type in an extension method. - (@ext [-> [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => { - extension_trait!(@ext [$($tail)*] -> [$($accum)* -> $f]); - }; - - // Parse a token. - (@ext [$token:tt $($tail:tt)*] -> [$($accum:tt)*]) => { - extension_trait!(@ext [$($tail)*] -> [$($accum)* $token]); - }; - - // Handle the end of the token list. - (@ext [] -> [$($accum:tt)*]) => { $($accum)* }; -}