chore: make #[doc(hidden)] apis private (#2901)

This commit is contained in:
Alice Ryhl 2020-10-02 06:13:28 +02:00 committed by GitHub
parent 13de30c53e
commit 7ec6d88b21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 18 deletions

View File

@ -55,8 +55,7 @@ impl ReadDir {
poll_fn(|cx| self.poll_next_entry(cx)).await poll_fn(|cx| self.poll_next_entry(cx)).await
} }
#[doc(hidden)] fn poll_next_entry(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<Option<DirEntry>>> {
pub fn poll_next_entry(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<Option<DirEntry>>> {
loop { loop {
match self.0 { match self.0 {
State::Idle(ref mut std) => { State::Idle(ref mut std) => {

View File

@ -83,8 +83,7 @@ impl<R> Lines<R>
where where
R: AsyncBufRead, R: AsyncBufRead,
{ {
#[doc(hidden)] fn poll_next_line(
pub fn poll_next_line(
self: Pin<&mut Self>, self: Pin<&mut Self>,
cx: &mut Context<'_>, cx: &mut Context<'_>,
) -> Poll<io::Result<Option<String>>> { ) -> Poll<io::Result<Option<String>>> {

View File

@ -65,8 +65,7 @@ impl<R> Split<R>
where where
R: AsyncBufRead, R: AsyncBufRead,
{ {
#[doc(hidden)] fn poll_next_segment(
pub fn poll_next_segment(
self: Pin<&mut Self>, self: Pin<&mut Self>,
cx: &mut Context<'_>, cx: &mut Context<'_>,
) -> Poll<io::Result<Option<Vec<u8>>>> { ) -> Poll<io::Result<Option<Vec<u8>>>> {

View File

@ -23,9 +23,7 @@ macro_rules! scoped_thread_local {
/// Type representing a thread local storage key corresponding to a reference /// Type representing a thread local storage key corresponding to a reference
/// to the type parameter `T`. /// to the type parameter `T`.
pub(crate) struct ScopedKey<T> { pub(crate) struct ScopedKey<T> {
#[doc(hidden)]
pub(crate) inner: &'static LocalKey<Cell<*const ()>>, pub(crate) inner: &'static LocalKey<Cell<*const ()>>,
#[doc(hidden)]
pub(crate) _marker: marker::PhantomData<T>, pub(crate) _marker: marker::PhantomData<T>,
} }

View File

@ -192,9 +192,13 @@ impl TcpStream {
Ok(TcpStream { io }) Ok(TcpStream { io })
} }
// Connects `TcpStream` asynchronously that may be built with a net2 `TcpBuilder`. /// Connects `TcpStream` asynchronously that may be built with a net2 `TcpBuilder`.
// ///
// This should be removed in favor of some in-crate TcpSocket builder API. /// This function is intended to be replaced with some sort of TcpSocket builder.
/// See https://github.com/tokio-rs/tokio/issues/2902
///
/// Despite being hidden, this function is part of the public API of Tokio v0.3, but
/// will be removed in v1.0 in favor of a better design.
#[doc(hidden)] #[doc(hidden)]
pub async fn connect_std(stream: net::TcpStream, addr: &SocketAddr) -> io::Result<TcpStream> { pub async fn connect_std(stream: net::TcpStream, addr: &SocketAddr) -> io::Result<TcpStream> {
let io = mio::net::TcpStream::connect_stream(stream, addr)?; let io = mio::net::TcpStream::connect_stream(stream, addr)?;

View File

@ -196,8 +196,7 @@ impl<T> Sender<T> {
Ok(()) Ok(())
} }
#[doc(hidden)] // TODO: remove fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()> {
pub fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()> {
// Keep track of task budget // Keep track of task budget
let coop = ready!(crate::coop::poll_proceed(cx)); let coop = ready!(crate::coop::poll_proceed(cx));

View File

@ -75,8 +75,10 @@ impl Future for OnClose<'_> {
type Output = bool; type Output = bool;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<bool> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<bool> {
let res = self.get_mut().tx.poll_closed(cx); let fut = self.get_mut().tx.closed();
Ready(res.is_ready()) crate::pin!(fut);
Ready(fut.poll(cx).is_ready())
} }
} }

View File

@ -122,8 +122,7 @@ pub struct Interval {
} }
impl Interval { impl Interval {
#[doc(hidden)] // TODO: document fn poll_tick(&mut self, cx: &mut Context<'_>) -> Poll<Instant> {
pub fn poll_tick(&mut self, cx: &mut Context<'_>) -> Poll<Instant> {
// Wait for the delay to be done // Wait for the delay to be done
ready!(Pin::new(&mut self.delay).poll(cx)); ready!(Pin::new(&mut self.delay).poll(cx));

View File

@ -6,11 +6,24 @@ use tokio_test::*;
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll};
trait AssertSend: Send {} trait AssertSend: Send {}
impl AssertSend for oneshot::Sender<i32> {} impl AssertSend for oneshot::Sender<i32> {}
impl AssertSend for oneshot::Receiver<i32> {} impl AssertSend for oneshot::Receiver<i32> {}
trait SenderExt {
fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()>;
}
impl<T> SenderExt for oneshot::Sender<T> {
fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()> {
tokio::pin! {
let fut = self.closed();
}
fut.poll(cx)
}
}
#[test] #[test]
fn send_recv() { fn send_recv() {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();

View File

@ -4,6 +4,7 @@
use tokio::time::{self, Duration, Instant}; use tokio::time::{self, Duration, Instant};
use tokio_test::{assert_pending, assert_ready_eq, task}; use tokio_test::{assert_pending, assert_ready_eq, task};
use std::future::Future;
use std::task::Poll; use std::task::Poll;
#[tokio::test] #[tokio::test]
@ -58,7 +59,12 @@ async fn usage_stream() {
} }
fn poll_next(interval: &mut task::Spawn<time::Interval>) -> Poll<Instant> { fn poll_next(interval: &mut task::Spawn<time::Interval>) -> Poll<Instant> {
interval.enter(|cx, mut interval| interval.poll_tick(cx)) interval.enter(|cx, mut interval| {
tokio::pin! {
let fut = interval.tick();
}
fut.poll(cx)
})
} }
fn ms(n: u64) -> Duration { fn ms(n: u64) -> Duration {