std/os/unix/
mod.rs

1//! Platform-specific extensions to `std` for Unix platforms.
2//!
3//! Provides access to platform-level information on Unix platforms, and
4//! exposes Unix-specific functions that would otherwise be inappropriate as
5//! part of the core `std` library.
6//!
7//! It exposes more ways to deal with platform-specific strings ([`OsStr`],
8//! [`OsString`]), allows to set permissions more granularly, extract low-level
9//! file descriptors from files and sockets, and has platform-specific helpers
10//! for spawning processes.
11//!
12//! # Examples
13//!
14//! ```no_run
15//! use std::fs::File;
16//! use std::os::unix::prelude::*;
17//!
18//! fn main() -> std::io::Result<()> {
19//!     let f = File::create("foo.txt")?;
20//!     let fd = f.as_raw_fd();
21//!
22//!     // use fd with native unix bindings
23//!
24//!     Ok(())
25//! }
26//! ```
27//!
28//! [`OsStr`]: crate::ffi::OsStr
29//! [`OsString`]: crate::ffi::OsString
30
31#![stable(feature = "rust1", since = "1.0.0")]
32#![doc(cfg(unix))]
33
34// Use linux as the default platform when documenting on other platforms like Windows
35#[cfg(doc)]
36use crate::os::linux as platform;
37
38#[cfg(not(doc))]
39mod platform {
40    #[cfg(target_os = "aix")]
41    pub use crate::os::aix::*;
42    #[cfg(target_os = "android")]
43    pub use crate::os::android::*;
44    #[cfg(target_vendor = "apple")]
45    pub use crate::os::darwin::*;
46    #[cfg(target_os = "dragonfly")]
47    pub use crate::os::dragonfly::*;
48    #[cfg(target_os = "emscripten")]
49    pub use crate::os::emscripten::*;
50    #[cfg(target_os = "espidf")]
51    pub use crate::os::espidf::*;
52    #[cfg(target_os = "freebsd")]
53    pub use crate::os::freebsd::*;
54    #[cfg(target_os = "fuchsia")]
55    pub use crate::os::fuchsia::*;
56    #[cfg(target_os = "haiku")]
57    pub use crate::os::haiku::*;
58    #[cfg(target_os = "horizon")]
59    pub use crate::os::horizon::*;
60    #[cfg(target_os = "hurd")]
61    pub use crate::os::hurd::*;
62    #[cfg(target_os = "illumos")]
63    pub use crate::os::illumos::*;
64    #[cfg(target_os = "l4re")]
65    pub use crate::os::l4re::*;
66    #[cfg(target_os = "linux")]
67    pub use crate::os::linux::*;
68    #[cfg(target_os = "netbsd")]
69    pub use crate::os::netbsd::*;
70    #[cfg(target_os = "nto")]
71    pub use crate::os::nto::*;
72    #[cfg(target_os = "nuttx")]
73    pub use crate::os::nuttx::*;
74    #[cfg(target_os = "openbsd")]
75    pub use crate::os::openbsd::*;
76    #[cfg(target_os = "redox")]
77    pub use crate::os::redox::*;
78    #[cfg(target_os = "rtems")]
79    pub use crate::os::rtems::*;
80    #[cfg(target_os = "solaris")]
81    pub use crate::os::solaris::*;
82    #[cfg(target_os = "vita")]
83    pub use crate::os::vita::*;
84    #[cfg(target_os = "vxworks")]
85    pub use crate::os::vxworks::*;
86}
87
88pub mod ffi;
89pub mod fs;
90pub mod io;
91pub mod net;
92pub mod process;
93pub mod raw;
94pub mod thread;
95
96/// A prelude for conveniently writing platform-specific code.
97///
98/// Includes all extension traits, and some important type definitions.
99#[stable(feature = "rust1", since = "1.0.0")]
100pub mod prelude {
101    #[doc(no_inline)]
102    #[stable(feature = "rust1", since = "1.0.0")]
103    pub use super::ffi::{OsStrExt, OsStringExt};
104    #[doc(no_inline)]
105    #[stable(feature = "rust1", since = "1.0.0")]
106    pub use super::fs::DirEntryExt;
107    #[doc(no_inline)]
108    #[stable(feature = "file_offset", since = "1.15.0")]
109    pub use super::fs::FileExt;
110    #[doc(no_inline)]
111    #[stable(feature = "rust1", since = "1.0.0")]
112    pub use super::fs::{FileTypeExt, MetadataExt, OpenOptionsExt, PermissionsExt};
113    #[doc(no_inline)]
114    #[stable(feature = "rust1", since = "1.0.0")]
115    pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
116    #[doc(no_inline)]
117    #[stable(feature = "rust1", since = "1.0.0")]
118    pub use super::process::{CommandExt, ExitStatusExt};
119    #[doc(no_inline)]
120    #[stable(feature = "rust1", since = "1.0.0")]
121    pub use super::thread::JoinHandleExt;
122}