Skip to content

Commit

Permalink
hide non-platform modules completely unless docsrs is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed May 9, 2021
1 parent 2c4c959 commit 010d477
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 363 deletions.
14 changes: 3 additions & 11 deletions tokio/src/io/async_fd.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
use crate::io::driver::{Handle, Interest, ReadyEvent, Registration};
use crate::os::unix::io::{AsRawFd, RawFd};

use mio::unix::SourceFd;
use std::io;
use std::{task::Context, task::Poll};

// helps rustdoc on non-supported platforms.
doc_prelude! {
mod mock {}

#[cfg(unix)] {
pub(super) use mio::unix::SourceFd;
}
}
use std::os::unix::io::{AsRawFd, RawFd};
use std::task::{Context, Poll};

/// Associates an IO object backed by a Unix file descriptor with the tokio
/// reactor, allowing for readiness to be polled. The file descriptor must be of
Expand Down
2 changes: 0 additions & 2 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,6 @@ mod util;
/// ```
pub mod stream {}

pub mod os;

cfg_macros! {
/// Implementation detail of the `select!` macro. This macro is **not**
/// intended to be used as part of the public API and is permitted to
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ macro_rules! doc_prelude {
$($items:tt)*
})*
) => {
#[cfg(all(doc, not(any($($($meta)*),*))))]
#[cfg(any(docsrs, not(any($($($meta)*),*))))]
#[doc(hidden)]
$vis mod doc {
$($mock_items)*
}

$(
#[cfg(any(not(doc), $($meta)*))]
#[cfg(all(not(docsrs), $($meta)*))]
#[doc(hidden)]
$vis mod doc {
$($items)*
Expand Down Expand Up @@ -220,7 +220,7 @@ macro_rules! cfg_net {
macro_rules! cfg_net_unix {
($($item:item)*) => {
$(
#[cfg(all(any(doc, unix), feature = "net"))]
#[cfg(all(any(docsrs, unix), feature = "net"))]
#[cfg_attr(docsrs, doc(cfg(all(unix, feature = "net"))))]
$item
)*
Expand Down
34 changes: 10 additions & 24 deletions tokio/src/net/unix/datagram/socket.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
use crate::io::{Interest, PollEvented, ReadBuf, Ready};
use crate::net::unix::SocketAddr;
use crate::os::unix::io::{AsRawFd, RawFd};
use crate::os::unix::net;

use std::convert::TryFrom;
use std::fmt;
use std::io;
use std::net::Shutdown;
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::os::unix::net;
use std::path::Path;
use std::task::{Context, Poll};

// helps rustdoc on non-supported platforms.
doc_prelude! {
mod mock {
pub(super) mod mio_net {
pub struct UnixDatagram(());
}
}

#[cfg(unix)] {
pub(super) use mio::net as mio_net;
pub(super) use std::os::unix::io::{FromRawFd, IntoRawFd};
}
}

cfg_io_util! {
use bytes::BufMut;
}
Expand Down Expand Up @@ -105,7 +91,7 @@ cfg_net_unix! {
/// # }
/// ```
pub struct UnixDatagram {
io: PollEvented<mio_net::UnixDatagram>,
io: PollEvented<mio::net::UnixDatagram>,
}
}

Expand Down Expand Up @@ -307,7 +293,7 @@ impl UnixDatagram {
where
P: AsRef<Path>,
{
let socket = mio_net::UnixDatagram::bind(path)?;
let socket = mio::net::UnixDatagram::bind(path)?;
UnixDatagram::new(socket)
}

Expand Down Expand Up @@ -341,7 +327,7 @@ impl UnixDatagram {
/// # }
/// ```
pub fn pair() -> io::Result<(UnixDatagram, UnixDatagram)> {
let (a, b) = mio_net::UnixDatagram::pair()?;
let (a, b) = mio::net::UnixDatagram::pair()?;
let a = UnixDatagram::new(a)?;
let b = UnixDatagram::new(b)?;

Expand Down Expand Up @@ -385,7 +371,7 @@ impl UnixDatagram {
/// # }
/// ```
pub fn from_std(datagram: net::UnixDatagram) -> io::Result<UnixDatagram> {
let socket = mio_net::UnixDatagram::from_std(datagram);
let socket = mio::net::UnixDatagram::from_std(datagram);
let io = PollEvented::new(socket)?;
Ok(UnixDatagram { io })
}
Expand All @@ -411,16 +397,16 @@ impl UnixDatagram {
/// ```
///
/// [`tokio::net::UnixDatagram`]: UnixDatagram
/// [`std::os::unix::net::UnixDatagram`]: crate::os::unix::net::UnixDatagram
/// [`set_nonblocking`]: fn@crate::os::unix::net::UnixDatagram::set_nonblocking
/// [`std::os::unix::net::UnixDatagram`]: std::os::unix::net::UnixDatagram
/// [`set_nonblocking`]: fn@std::os::unix::net::UnixDatagram::set_nonblocking
pub fn into_std(self) -> io::Result<net::UnixDatagram> {
self.io
.into_inner()
.map(|io| io.into_raw_fd())
.map(|raw_fd| unsafe { net::UnixDatagram::from_raw_fd(raw_fd) })
}

fn new(socket: mio_net::UnixDatagram) -> io::Result<UnixDatagram> {
fn new(socket: mio::net::UnixDatagram) -> io::Result<UnixDatagram> {
let io = PollEvented::new(socket)?;
Ok(UnixDatagram { io })
}
Expand Down Expand Up @@ -457,7 +443,7 @@ impl UnixDatagram {
/// # }
/// ```
pub fn unbound() -> io::Result<UnixDatagram> {
let socket = mio_net::UnixDatagram::unbound()?;
let socket = mio::net::UnixDatagram::unbound()?;
UnixDatagram::new(socket)
}

Expand Down
28 changes: 7 additions & 21 deletions tokio/src/net/unix/listener.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
use crate::io::{Interest, PollEvented};
use crate::net::unix::{SocketAddr, UnixStream};
use crate::os::unix::io::{AsRawFd, RawFd};
use crate::os::unix::net;

use std::convert::TryFrom;
use std::fmt;
use std::io;
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::os::unix::net;
use std::path::Path;
use std::task::{Context, Poll};

// helps rustdoc on non-supported platforms.
doc_prelude! {
mod mock {
pub(super) mod mio_net {
pub type UnixListener = ();
}
}

#[cfg(unix)] {
pub(super) use mio::net as mio_net;
pub(super) use std::os::unix::io::{FromRawFd, IntoRawFd};
}
}

cfg_net_unix! {
/// A Unix socket which can accept connections from other Unix sockets.
///
Expand Down Expand Up @@ -59,7 +45,7 @@ cfg_net_unix! {
/// }
/// ```
pub struct UnixListener {
io: PollEvented<mio_net::UnixListener>,
io: PollEvented<mio::net::UnixListener>,
}
}

Expand All @@ -77,7 +63,7 @@ impl UnixListener {
where
P: AsRef<Path>,
{
let listener = mio_net::UnixListener::bind(path)?;
let listener = mio::net::UnixListener::bind(path)?;
let io = PollEvented::new(listener)?;
Ok(UnixListener { io })
}
Expand All @@ -97,7 +83,7 @@ impl UnixListener {
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn from_std(listener: net::UnixListener) -> io::Result<UnixListener> {
let listener = mio_net::UnixListener::from_std(listener);
let listener = mio::net::UnixListener::from_std(listener);
let io = PollEvented::new(listener)?;
Ok(UnixListener { io })
}
Expand All @@ -122,8 +108,8 @@ impl UnixListener {
/// ```
///
/// [`tokio::net::UnixListener`]: UnixListener
/// [`std::os::unix::net::UnixListener`]: crate::os::unix::net::UnixListener
/// [`set_nonblocking`]: fn@crate::os::unix::net::UnixListener::set_nonblocking
/// [`std::os::unix::net::UnixListener`]: std::os::unix::net::UnixListener
/// [`set_nonblocking`]: fn@std::os::unix::net::UnixListener::set_nonblocking
pub fn into_std(self) -> io::Result<net::UnixListener> {
self.io
.into_inner()
Expand Down
19 changes: 3 additions & 16 deletions tokio/src/net/unix/socketaddr.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
use std::fmt;
use std::path::Path;

// helps rustdoc on non-supported platforms.
doc_prelude! {
mod mock {
pub(super) mod mio_net {
pub struct SocketAddr(());
}
}

#[cfg(unix)] {
pub(super) use mio::net as mio_net;
}
}

/// An address associated with a Tokio Unix socket.
pub struct SocketAddr(pub(super) mio_net::SocketAddr);
pub struct SocketAddr(pub(super) mio::net::SocketAddr);

impl SocketAddr {
/// Returns `true` if the address is unnamed.
///
/// Documentation reflected in [`SocketAddr`]
///
/// [`SocketAddr`]: crate::os::unix::net::SocketAddr
/// [`SocketAddr`]: std::os::unix::net::SocketAddr
pub fn is_unnamed(&self) -> bool {
self.0.is_unnamed()
}
Expand All @@ -31,7 +18,7 @@ impl SocketAddr {
///
/// Documentation reflected in [`SocketAddr`]
///
/// [`SocketAddr`]: crate::os::unix::net::SocketAddr
/// [`SocketAddr`]: std::os::unix::net::SocketAddr
pub fn as_pathname(&self) -> Option<&Path> {
self.0.as_pathname()
}
Expand Down
35 changes: 11 additions & 24 deletions tokio/src/net/unix/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,18 @@ use crate::net::unix::split::{split, ReadHalf, WriteHalf};
use crate::net::unix::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf};
use crate::net::unix::ucred::{self, UCred};
use crate::net::unix::SocketAddr;
use crate::os::unix::io::{AsRawFd, RawFd};
use crate::os::unix::net;

use std::convert::TryFrom;
use std::fmt;
use std::io::{self, Read, Write};
use std::net::Shutdown;
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::os::unix::io::{FromRawFd, IntoRawFd};
use std::os::unix::net;
use std::path::Path;
use std::pin::Pin;
use std::task::{Context, Poll};

// helps rustdoc on non-supported platforms.
doc_prelude! {
mod mock {
pub(super) mod mio_net {
pub struct UnixStream(());
}
}

#[cfg(unix)] {
pub(super) use std::os::unix::io::{FromRawFd, IntoRawFd};
pub(super) use mio::net as mio_net;
}
}

cfg_io_util! {
use bytes::BufMut;
}
Expand All @@ -47,7 +34,7 @@ cfg_net_unix! {
///
/// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown
pub struct UnixStream {
io: PollEvented<mio_net::UnixStream>,
io: PollEvented<mio::net::UnixStream>,
}
}

Expand All @@ -61,7 +48,7 @@ impl UnixStream {
where
P: AsRef<Path>,
{
let stream = mio_net::UnixStream::connect(path)?;
let stream = mio::net::UnixStream::connect(path)?;
let stream = UnixStream::new(stream)?;

poll_fn(|cx| stream.io.registration().poll_write_ready(cx)).await?;
Expand Down Expand Up @@ -516,7 +503,7 @@ impl UnixStream {
/// from a future driven by a tokio runtime, otherwise runtime can be set
/// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.
pub fn from_std(stream: net::UnixStream) -> io::Result<UnixStream> {
let stream = mio_net::UnixStream::from_std(stream);
let stream = mio::net::UnixStream::from_std(stream);
let io = PollEvented::new(stream)?;

Ok(UnixStream { io })
Expand Down Expand Up @@ -558,8 +545,8 @@ impl UnixStream {
/// }
/// ```
/// [`tokio::net::UnixStream`]: UnixStream
/// [`std::os::unix::net::UnixStream`]: crate::os::unix::net::UnixStream
/// [`set_nonblocking`]: fn@crate::os::unix::net::UnixStream::set_nonblocking
/// [`std::os::unix::net::UnixStream`]: std::os::unix::net::UnixStream
/// [`set_nonblocking`]: fn@std::os::unix::net::UnixStream::set_nonblocking
pub fn into_std(self) -> io::Result<net::UnixStream> {
self.io
.into_inner()
Expand All @@ -573,14 +560,14 @@ impl UnixStream {
/// communicating back and forth between one another. Each socket will
/// be associated with the default event loop's handle.
pub fn pair() -> io::Result<(UnixStream, UnixStream)> {
let (a, b) = mio_net::UnixStream::pair()?;
let (a, b) = mio::net::UnixStream::pair()?;
let a = UnixStream::new(a)?;
let b = UnixStream::new(b)?;

Ok((a, b))
}

pub(crate) fn new(stream: mio_net::UnixStream) -> io::Result<UnixStream> {
pub(crate) fn new(stream: mio::net::UnixStream) -> io::Result<UnixStream> {
let io = PollEvented::new(stream)?;
Ok(UnixStream { io })
}
Expand Down Expand Up @@ -644,7 +631,7 @@ impl UnixStream {
}
}

impl TryFrom<net::UnixStream> for super::UnixStream {
impl TryFrom<net::UnixStream> for UnixStream {
type Error = io::Error;

/// Consumes stream, returning the tokio I/O object.
Expand Down
14 changes: 1 addition & 13 deletions tokio/src/net/unix/ucred.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// helps rustdoc on non-supported platforms.
doc_prelude! {
mod mock {
#![allow(non_camel_case_types)]
pub(super) struct gid_t(());
pub(super) struct pid_t(());
pub(super) struct uid_t(());
}

#[cfg(unix)] {
pub(super) use libc::{gid_t, pid_t, uid_t};
}
}
use libc::{gid_t, pid_t, uid_t};

/// Credentials of a process
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
Expand Down
Loading

0 comments on commit 010d477

Please sign in to comment.