Skip to content

Commit c76cda9

Browse files
authored
Rollup merge of rust-lang#98368 - sunfishcode:sunfishcode/std-os-fd, r=joshtriplett
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` r? ``@joshtriplett``
2 parents 09ae784 + a7f3ba9 commit c76cda9

File tree

10 files changed

+29
-49
lines changed

10 files changed

+29
-49
lines changed

library/std/src/os/fd/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
//! Owned and borrowed Unix-like file descriptors.
2+
//!
3+
//! This module is supported on Unix platforms and WASI, which both use a
4+
//! similar file descriptor system for referencing OS resources.
25
36
#![stable(feature = "io_safety", since = "1.63.0")]
47
#![deny(unsafe_op_in_unsafe_fn)]
58

69
// `RawFd`, `AsRawFd`, etc.
7-
pub mod raw;
10+
mod raw;
811

912
// `OwnedFd`, `AsFd`, etc.
10-
pub mod owned;
13+
mod owned;
1114

1215
// Implementations for `AsRawFd` etc. for network types.
1316
mod net;
1417

1518
#[cfg(test)]
1619
mod tests;
20+
21+
// Export the types and traits for the public API.
22+
#[unstable(feature = "os_fd", issue = "98699")]
23+
pub use owned::*;
24+
#[unstable(feature = "os_fd", issue = "98699")]
25+
pub use raw::*;

library/std/src/os/fd/owned.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,8 @@ pub trait AsFd {
206206
/// ```rust,no_run
207207
/// use std::fs::File;
208208
/// # use std::io;
209-
/// # #[cfg(target_os = "wasi")]
210-
/// # use std::os::wasi::io::{AsFd, BorrowedFd};
211-
/// # #[cfg(unix)]
212-
/// # use std::os::unix::io::{AsFd, BorrowedFd};
209+
/// # #[cfg(any(unix, target_os = "wasi"))]
210+
/// # use std::os::fd::{AsFd, BorrowedFd};
213211
///
214212
/// let mut f = File::open("foo.txt")?;
215213
/// # #[cfg(any(unix, target_os = "wasi"))]

library/std/src/os/fd/raw.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ pub trait AsRawFd {
4242
/// ```no_run
4343
/// use std::fs::File;
4444
/// # use std::io;
45-
/// #[cfg(unix)]
46-
/// use std::os::unix::io::{AsRawFd, RawFd};
47-
/// #[cfg(target_os = "wasi")]
48-
/// use std::os::wasi::io::{AsRawFd, RawFd};
45+
/// #[cfg(any(unix, target_os = "wasi"))]
46+
/// use std::os::fd::{AsRawFd, RawFd};
4947
///
5048
/// let mut f = File::open("foo.txt")?;
5149
/// // Note that `raw_fd` is only valid as long as `f` exists.
@@ -83,10 +81,8 @@ pub trait FromRawFd {
8381
/// ```no_run
8482
/// use std::fs::File;
8583
/// # use std::io;
86-
/// #[cfg(unix)]
87-
/// use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
88-
/// #[cfg(target_os = "wasi")]
89-
/// use std::os::wasi::io::{FromRawFd, IntoRawFd, RawFd};
84+
/// #[cfg(any(unix, target_os = "wasi"))]
85+
/// use std::os::fd::{FromRawFd, IntoRawFd, RawFd};
9086
///
9187
/// let f = File::open("foo.txt")?;
9288
/// # #[cfg(any(unix, target_os = "wasi"))]
@@ -121,10 +117,8 @@ pub trait IntoRawFd {
121117
/// ```no_run
122118
/// use std::fs::File;
123119
/// # use std::io;
124-
/// #[cfg(unix)]
125-
/// use std::os::unix::io::{IntoRawFd, RawFd};
126-
/// #[cfg(target_os = "wasi")]
127-
/// use std::os::wasi::io::{IntoRawFd, RawFd};
120+
/// #[cfg(any(unix, target_os = "wasi"))]
121+
/// use std::os::fd::{IntoRawFd, RawFd};
128122
///
129123
/// let f = File::open("foo.txt")?;
130124
/// #[cfg(any(unix, target_os = "wasi"))]

library/std/src/os/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub mod solid;
147147
pub mod vxworks;
148148

149149
#[cfg(any(unix, target_os = "wasi", doc))]
150-
mod fd;
150+
pub mod fd;
151151

152152
#[cfg(any(target_os = "linux", target_os = "android", doc))]
153153
mod net;

library/std/src/os/unix/io/fd.rs

-8
This file was deleted.

library/std/src/os/unix/io/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@
7777
7878
#![stable(feature = "rust1", since = "1.0.0")]
7979

80-
mod fd;
81-
mod raw;
82-
83-
#[stable(feature = "io_safety", since = "1.63.0")]
84-
pub use fd::*;
8580
#[stable(feature = "rust1", since = "1.0.0")]
86-
pub use raw::*;
81+
pub use crate::os::fd::*;
82+
83+
// Tests for this module
84+
#[cfg(test)]
85+
mod tests;

library/std/src/os/unix/io/raw.rs

-6
This file was deleted.
File renamed without changes.

library/std/src/os/wasi/io/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
//! WASI-specific extensions to general I/O primitives.
22
3-
#![deny(unsafe_op_in_unsafe_fn)]
43
#![unstable(feature = "wasi_ext", issue = "71213")]
54

6-
mod fd;
7-
mod raw;
8-
9-
#[unstable(feature = "wasi_ext", issue = "71213")]
10-
pub use fd::*;
115
#[unstable(feature = "wasi_ext", issue = "71213")]
12-
pub use raw::*;
6+
pub use crate::os::fd::*;

src/test/rustdoc-js-std/asrawfd.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const EXPECTED = {
66
'others': [
77
// Reproduction test for https://github.com/rust-lang/rust/issues/78724
88
// Validate that type alias methods get the correct path.
9-
{ 'path': 'std::os::unix::io::AsRawFd', 'name': 'as_raw_fd' },
10-
{ 'path': 'std::os::wasi::io::AsRawFd', 'name': 'as_raw_fd' },
9+
{ 'path': 'std::os::fd::AsRawFd', 'name': 'as_raw_fd' },
10+
{ 'path': 'std::os::fd::AsRawFd', 'name': 'as_raw_fd' },
1111
{ 'path': 'std::os::linux::process::PidFd', 'name': 'as_raw_fd' },
12-
{ 'path': 'std::os::unix::io::RawFd', 'name': 'as_raw_fd' },
12+
{ 'path': 'std::os::fd::RawFd', 'name': 'as_raw_fd' },
1313
],
1414
};

0 commit comments

Comments
 (0)