Skip to content

Commit c846a2a

Browse files
committed
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`
1 parent b96fa1a commit c846a2a

File tree

9 files changed

+23
-46
lines changed

9 files changed

+23
-46
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
//! Owned and borrowed Unix-like file descriptors.
2+
//!
3+
//! This module is supported on Unix platforms, and also some non-Unix
4+
//! platforms which use a similar file descriptor system for referencing OS
5+
//! resources.
26
37
#![stable(feature = "io_safety", since = "1.63.0")]
48
#![deny(unsafe_op_in_unsafe_fn)]
59

610
// `RawFd`, `AsRawFd`, etc.
7-
pub mod raw;
11+
mod raw;
812

913
// `OwnedFd`, `AsFd`, etc.
10-
pub mod owned;
14+
mod owned;
1115

1216
// Implementations for `AsRawFd` etc. for network types.
1317
mod net;
1418

1519
#[cfg(test)]
1620
mod tests;
21+
22+
// Export the types and traits for the public API.
23+
#[stable(feature = "io_safety", since = "1.63.0")]
24+
pub use owned::*;
25+
#[stable(feature = "rust1", since = "1.0.0")]
26+
pub use raw::*;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,7 @@ pub trait AsFd {
205205
/// ```rust,no_run
206206
/// use std::fs::File;
207207
/// # use std::io;
208-
/// # #[cfg(target_os = "wasi")]
209-
/// # use std::os::wasi::io::{AsFd, BorrowedFd};
210-
/// # #[cfg(unix)]
211-
/// # use std::os::unix::io::{AsFd, BorrowedFd};
208+
/// # use std::os::fd::{AsFd, BorrowedFd};
212209
///
213210
/// let mut f = File::open("foo.txt")?;
214211
/// # #[cfg(any(unix, target_os = "wasi"))]

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ 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+
/// use std::os::fd::{AsRawFd, RawFd};
4946
///
5047
/// let mut f = File::open("foo.txt")?;
5148
/// // Note that `raw_fd` is only valid as long as `f` exists.
@@ -83,10 +80,7 @@ pub trait FromRawFd {
8380
/// ```no_run
8481
/// use std::fs::File;
8582
/// # 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};
83+
/// use std::os::fd::{FromRawFd, IntoRawFd, RawFd};
9084
///
9185
/// let f = File::open("foo.txt")?;
9286
/// # #[cfg(any(unix, target_os = "wasi"))]
@@ -121,10 +115,7 @@ pub trait IntoRawFd {
121115
/// ```no_run
122116
/// use std::fs::File;
123117
/// # 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};
118+
/// use std::os::fd::{IntoRawFd, RawFd};
128119
///
129120
/// let f = File::open("foo.txt")?;
130121
/// #[cfg(any(unix, target_os = "wasi"))]

library/std/src/os/mod.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 8 deletions
This file was deleted.

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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 1 addition & 7 deletions
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::*;

0 commit comments

Comments
 (0)