Make std::os::fd public.

`std::os::fd` defines types like `OwnedFd` and `RawFd` and is common
between Unix and non-Unix platforms that share a basic file-descriptor
concept. Rust currently uses this internally to simplify its own code,
but it would be useful for external users in the same way, so make it
public.

This means that `OwnedFd` etc. will all appear in three places, for
example on unix platforms:
 - `std::os::fd::OwnedFd`
 - `std::os::unix::io::OwnedFd`
 - `std::os::unix::prelude::OwnedFd`
This commit is contained in:
Dan Gohman 2022-06-14 10:44:14 -07:00
parent b96fa1a25c
commit c846a2af8d
9 changed files with 23 additions and 46 deletions

View File

@ -1,16 +1,26 @@
//! Owned and borrowed Unix-like file descriptors.
//!
//! This module is supported on Unix platforms, and also some non-Unix
//! platforms which use a similar file descriptor system for referencing OS
//! resources.
#![stable(feature = "io_safety", since = "1.63.0")]
#![deny(unsafe_op_in_unsafe_fn)]
// `RawFd`, `AsRawFd`, etc.
pub mod raw;
mod raw;
// `OwnedFd`, `AsFd`, etc.
pub mod owned;
mod owned;
// Implementations for `AsRawFd` etc. for network types.
mod net;
#[cfg(test)]
mod tests;
// Export the types and traits for the public API.
#[stable(feature = "io_safety", since = "1.63.0")]
pub use owned::*;
#[stable(feature = "rust1", since = "1.0.0")]
pub use raw::*;

View File

@ -205,10 +205,7 @@ pub trait AsFd {
/// ```rust,no_run
/// use std::fs::File;
/// # use std::io;
/// # #[cfg(target_os = "wasi")]
/// # use std::os::wasi::io::{AsFd, BorrowedFd};
/// # #[cfg(unix)]
/// # use std::os::unix::io::{AsFd, BorrowedFd};
/// # use std::os::fd::{AsFd, BorrowedFd};
///
/// let mut f = File::open("foo.txt")?;
/// # #[cfg(any(unix, target_os = "wasi"))]

View File

@ -42,10 +42,7 @@ pub trait AsRawFd {
/// ```no_run
/// use std::fs::File;
/// # use std::io;
/// #[cfg(unix)]
/// use std::os::unix::io::{AsRawFd, RawFd};
/// #[cfg(target_os = "wasi")]
/// use std::os::wasi::io::{AsRawFd, RawFd};
/// use std::os::fd::{AsRawFd, RawFd};
///
/// let mut f = File::open("foo.txt")?;
/// // Note that `raw_fd` is only valid as long as `f` exists.
@ -83,10 +80,7 @@ pub trait FromRawFd {
/// ```no_run
/// use std::fs::File;
/// # use std::io;
/// #[cfg(unix)]
/// use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
/// #[cfg(target_os = "wasi")]
/// use std::os::wasi::io::{FromRawFd, IntoRawFd, RawFd};
/// use std::os::fd::{FromRawFd, IntoRawFd, RawFd};
///
/// let f = File::open("foo.txt")?;
/// # #[cfg(any(unix, target_os = "wasi"))]
@ -121,10 +115,7 @@ pub trait IntoRawFd {
/// ```no_run
/// use std::fs::File;
/// # use std::io;
/// #[cfg(unix)]
/// use std::os::unix::io::{IntoRawFd, RawFd};
/// #[cfg(target_os = "wasi")]
/// use std::os::wasi::io::{IntoRawFd, RawFd};
/// use std::os::fd::{IntoRawFd, RawFd};
///
/// let f = File::open("foo.txt")?;
/// #[cfg(any(unix, target_os = "wasi"))]

View File

@ -147,7 +147,7 @@ pub mod windows {}
pub mod vxworks;
#[cfg(any(unix, target_os = "wasi", doc))]
mod fd;
pub mod fd;
#[cfg(any(target_os = "linux", target_os = "android", doc))]
mod net;

View File

@ -1,8 +0,0 @@
//! Owned and borrowed file descriptors.
// Tests for this module
#[cfg(test)]
mod tests;
#[stable(feature = "io_safety", since = "1.63.0")]
pub use crate::os::fd::owned::*;

View File

@ -77,10 +77,9 @@
#![stable(feature = "rust1", since = "1.0.0")]
mod fd;
mod raw;
#[stable(feature = "io_safety", since = "1.63.0")]
pub use fd::*;
#[stable(feature = "rust1", since = "1.0.0")]
pub use raw::*;
pub use crate::os::fd::*;
// Tests for this module
#[cfg(test)]
mod tests;

View File

@ -1,6 +0,0 @@
//! Unix-specific extensions to general I/O primitives.
#![stable(feature = "rust1", since = "1.0.0")]
#[stable(feature = "rust1", since = "1.0.0")]
pub use crate::os::fd::raw::*;

View File

@ -1,12 +1,6 @@
//! WASI-specific extensions to general I/O primitives.
#![deny(unsafe_op_in_unsafe_fn)]
#![unstable(feature = "wasi_ext", issue = "71213")]
mod fd;
mod raw;
#[unstable(feature = "wasi_ext", issue = "71213")]
pub use fd::*;
#[unstable(feature = "wasi_ext", issue = "71213")]
pub use raw::*;
pub use crate::os::fd::*;