mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-30 17:25:32 +00:00
Remove docs
-only features from extension_trait
.
This is the `@doc` rules, the shim trait impls, and the imports.
This commit is contained in:
parent
f56a8d6935
commit
ed2fcce557
7 changed files with 1 additions and 347 deletions
|
@ -21,11 +21,6 @@ cfg_unstable_default! {
|
|||
}
|
||||
|
||||
extension_trait! {
|
||||
use core::pin::Pin;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
#[doc = r#"
|
||||
A future represents an asynchronous computation.
|
||||
|
||||
|
@ -393,40 +388,4 @@ extension_trait! {
|
|||
TimeoutFuture::new(self, dur)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Future + Unpin + ?Sized> Future for Box<F> {
|
||||
type Output = F::Output;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Future + Unpin + ?Sized> Future for &mut F {
|
||||
type Output = F::Output;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> Future for Pin<P>
|
||||
where
|
||||
P: DerefMut + Unpin,
|
||||
<P as Deref>::Target: Future,
|
||||
{
|
||||
type Output = <<P as Deref>::Target as Future>::Output;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Future> Future for std::panic::AssertUnwindSafe<F> {
|
||||
type Output = F::Output;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ use crate::io;
|
|||
use crate::task::{Context, Poll};
|
||||
|
||||
extension_trait! {
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
#[doc = r#"
|
||||
Allows reading from a buffered byte stream.
|
||||
|
||||
|
@ -283,62 +281,6 @@ extension_trait! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: BufRead + Unpin + ?Sized> BufRead for Box<T> {
|
||||
fn poll_fill_buf(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<io::Result<&[u8]>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn consume(self: Pin<&mut Self>, amt: usize) {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: BufRead + Unpin + ?Sized> BufRead for &mut T {
|
||||
fn poll_fill_buf(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<io::Result<&[u8]>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn consume(self: Pin<&mut Self>, amt: usize) {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> BufRead for Pin<P>
|
||||
where
|
||||
P: DerefMut + Unpin,
|
||||
<P as Deref>::Target: BufRead,
|
||||
{
|
||||
fn poll_fill_buf(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<io::Result<&[u8]>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn consume(self: Pin<&mut Self>, amt: usize) {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl BufRead for &[u8] {
|
||||
fn poll_fill_buf(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<io::Result<&[u8]>> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn consume(self: Pin<&mut Self>, amt: usize) {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_until_internal<R: BufReadExt + ?Sized>(
|
||||
|
|
|
@ -22,12 +22,6 @@ pub use chain::Chain;
|
|||
pub use take::Take;
|
||||
|
||||
extension_trait! {
|
||||
use std::pin::Pin;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use crate::io;
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
#[doc = r#"
|
||||
Allows reading from a byte stream.
|
||||
|
||||
|
@ -422,50 +416,6 @@ extension_trait! {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
impl<T: Read + Unpin + ?Sized> Read for Box<T> {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Read + Unpin + ?Sized> Read for &mut T {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> Read for Pin<P>
|
||||
where
|
||||
P: DerefMut + Unpin,
|
||||
<P as Deref>::Target: Read,
|
||||
{
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for &[u8] {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes a buffer if necessary.
|
||||
|
|
|
@ -5,12 +5,6 @@ use seek::SeekFuture;
|
|||
use crate::io::SeekFrom;
|
||||
|
||||
extension_trait! {
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::io;
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
#[doc = r#"
|
||||
Allows seeking through a byte stream.
|
||||
|
||||
|
@ -83,38 +77,4 @@ extension_trait! {
|
|||
SeekFuture { seeker: self, pos }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Seek + Unpin + ?Sized> Seek for Box<T> {
|
||||
fn poll_seek(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
pos: SeekFrom,
|
||||
) -> Poll<io::Result<u64>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Seek + Unpin + ?Sized> Seek for &mut T {
|
||||
fn poll_seek(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
pos: SeekFrom,
|
||||
) -> Poll<io::Result<u64>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> Seek for Pin<P>
|
||||
where
|
||||
P: DerefMut + Unpin,
|
||||
<P as Deref>::Target: Seek,
|
||||
{
|
||||
fn poll_seek(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
pos: SeekFrom,
|
||||
) -> Poll<io::Result<u64>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,6 @@ use write_vectored::WriteVectoredFuture;
|
|||
use crate::io::{self, IoSlice};
|
||||
|
||||
extension_trait! {
|
||||
use std::pin::Pin;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
#[doc = r#"
|
||||
Allows writing to a byte stream.
|
||||
|
||||
|
@ -245,80 +240,4 @@ extension_trait! {
|
|||
WriteFmtFuture { writer: self, res: Some(res), buffer: None, amt: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Write + Unpin + ?Sized> Write for Box<T> {
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Write + Unpin + ?Sized> Write for &mut T {
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> Write for Pin<P>
|
||||
where
|
||||
P: DerefMut + Unpin,
|
||||
<P as Deref>::Target: Write,
|
||||
{
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for Vec<u8> {
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
|
||||
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,10 +144,6 @@ cfg_unstable! {
|
|||
}
|
||||
|
||||
extension_trait! {
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
#[doc = r#"
|
||||
An asynchronous stream of values.
|
||||
|
||||
|
@ -2389,40 +2385,4 @@ extension_trait! {
|
|||
Product::product(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Stream + Unpin + ?Sized> Stream for Box<S> {
|
||||
type Item = S::Item;
|
||||
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Stream + Unpin + ?Sized> Stream for &mut S {
|
||||
type Item = S::Item;
|
||||
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> Stream for Pin<P>
|
||||
where
|
||||
P: DerefMut + Unpin,
|
||||
<P as Deref>::Target: Stream,
|
||||
{
|
||||
type Item = <<P as Deref>::Target as Stream>::Item;
|
||||
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Stream> Stream for std::panic::AssertUnwindSafe<S> {
|
||||
type Item = S::Item;
|
||||
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
unreachable!("this impl only appears in the rendered docs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
38
src/utils.rs
38
src/utils.rs
|
@ -259,26 +259,8 @@ macro_rules! extension_trait {
|
|||
pub trait $ext:ident: $base:path {
|
||||
$($body_ext:tt)*
|
||||
}
|
||||
|
||||
// Shim trait impls that only appear in docs.
|
||||
$($imp:item)*
|
||||
) => {
|
||||
// A fake `impl Future` type that doesn't borrow.
|
||||
#[allow(dead_code)]
|
||||
mod owned {
|
||||
#[doc(hidden)]
|
||||
pub struct ImplFuture<T>(core::marker::PhantomData<T>);
|
||||
}
|
||||
|
||||
// Render a fake trait combining the bodies of the base trait and the extension trait.
|
||||
#[cfg(feature = "docs")]
|
||||
#[doc = $doc]
|
||||
pub trait $name {
|
||||
extension_trait!(@doc [$($body_base)* $($body_ext)*] -> []);
|
||||
}
|
||||
|
||||
// When not rendering docs, re-export the base trait from the futures crate.
|
||||
#[cfg(not(feature = "docs"))]
|
||||
// Re-export the base trait from the futures crate.
|
||||
pub use $base as $name;
|
||||
|
||||
// The extension trait that adds methods to any type implementing the base trait.
|
||||
|
@ -289,36 +271,18 @@ macro_rules! extension_trait {
|
|||
|
||||
// Blanket implementation of the extension trait for any type implementing the base trait.
|
||||
impl<T: $name + ?Sized> $ext for T {}
|
||||
|
||||
// Shim trait impls that only appear in docs.
|
||||
$(#[cfg(feature = "docs")] $imp)*
|
||||
};
|
||||
|
||||
// Parse the return type in an extension method.
|
||||
(@doc [-> impl Future<Output = $out:ty> [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => {
|
||||
extension_trait!(@doc [$($tail)*] -> [$($accum)* -> owned::ImplFuture<$out>]);
|
||||
};
|
||||
(@ext [-> impl Future<Output = $out:ty> [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => {
|
||||
extension_trait!(@ext [$($tail)*] -> [$($accum)* -> $f]);
|
||||
};
|
||||
|
||||
// Parse a token.
|
||||
(@doc [$token:tt $($tail:tt)*] -> [$($accum:tt)*]) => {
|
||||
extension_trait!(@doc [$($tail)*] -> [$($accum)* $token]);
|
||||
};
|
||||
(@ext [$token:tt $($tail:tt)*] -> [$($accum:tt)*]) => {
|
||||
extension_trait!(@ext [$($tail)*] -> [$($accum)* $token]);
|
||||
};
|
||||
|
||||
// Handle the end of the token list.
|
||||
(@doc [] -> [$($accum:tt)*]) => { $($accum)* };
|
||||
(@ext [] -> [$($accum:tt)*]) => { $($accum)* };
|
||||
|
||||
// Parse imports at the beginning of the macro.
|
||||
($import:item $($tail:tt)*) => {
|
||||
#[cfg(feature = "docs")]
|
||||
$import
|
||||
|
||||
extension_trait!($($tail)*);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue