Skip to main content

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#![cfg_attr(target_family = "unix", doc = "```no_run")]
15#![cfg_attr(not(target_family = "unix"), doc = "```ignore (needs unix)")]
16//! use std::fs::File;
17//! use std::os::unix::prelude::*;
18//!
19//! fn main() -> std::io::Result<()> {
20//!     let f = File::create("foo.txt")?;
21//!     let fd = f.as_raw_fd();
22//!
23//!     // use fd with native unix bindings
24//!
25//!     Ok(())
26//! }
27//! ```
28//!
29//! [`OsStr`]: crate::ffi::OsStr
30//! [`OsString`]: crate::ffi::OsString
31
32#![stable(feature = "rust1", since = "1.0.0")]
33#![doc(cfg(unix))]
34
35// Use linux as the default platform when documenting on other platforms like Windows
36#[cfg(doc)]
37use crate::os::linux as platform;
38
39#[cfg(not(doc))]
40mod platform {
41    #[cfg(target_os = "aix")]
42    pub use crate::os::aix::*;
43    #[cfg(target_os = "android")]
44    pub use crate::os::android::*;
45    #[cfg(target_os = "cygwin")]
46    pub use crate::os::cygwin::*;
47    #[cfg(target_vendor = "apple")]
48    pub use crate::os::darwin::*;
49    #[cfg(target_os = "dragonfly")]
50    pub use crate::os::dragonfly::*;
51    #[cfg(target_os = "emscripten")]
52    pub use crate::os::emscripten::*;
53    #[cfg(target_os = "espidf")]
54    pub use crate::os::espidf::*;
55    #[cfg(target_os = "freebsd")]
56    pub use crate::os::freebsd::*;
57    #[cfg(target_os = "fuchsia")]
58    pub use crate::os::fuchsia::*;
59    #[cfg(target_os = "haiku")]
60    pub use crate::os::haiku::*;
61    #[cfg(target_os = "horizon")]
62    pub use crate::os::horizon::*;
63    #[cfg(target_os = "hurd")]
64    pub use crate::os::hurd::*;
65    #[cfg(target_os = "illumos")]
66    pub use crate::os::illumos::*;
67    #[cfg(target_os = "l4re")]
68    pub use crate::os::l4re::*;
69    #[cfg(target_os = "linux")]
70    pub use crate::os::linux::*;
71    #[cfg(target_os = "netbsd")]
72    pub use crate::os::netbsd::*;
73    #[cfg(any(target_os = "nto", target_os = "qnx"))]
74    pub use crate::os::nto::*;
75    #[cfg(target_os = "nuttx")]
76    pub use crate::os::nuttx::*;
77    #[cfg(target_os = "openbsd")]
78    pub use crate::os::openbsd::*;
79    #[cfg(target_os = "redox")]
80    pub use crate::os::redox::*;
81    #[cfg(target_os = "rtems")]
82    pub use crate::os::rtems::*;
83    #[cfg(target_os = "solaris")]
84    pub use crate::os::solaris::*;
85    #[cfg(target_os = "vita")]
86    pub use crate::os::vita::*;
87    #[cfg(target_os = "vxworks")]
88    pub use crate::os::vxworks::*;
89}
90
91pub mod ffi;
92pub mod fs;
93pub mod io;
94pub mod net;
95pub mod process;
96pub mod raw;
97pub mod thread;
98pub mod xdg;
99
100/// A prelude for conveniently writing platform-specific code.
101///
102/// Includes all extension traits, and some important type definitions.
103#[stable(feature = "rust1", since = "1.0.0")]
104pub mod prelude {
105    #[doc(no_inline)]
106    #[stable(feature = "rust1", since = "1.0.0")]
107    pub use super::ffi::{OsStrExt, OsStringExt};
108    #[doc(no_inline)]
109    #[stable(feature = "rust1", since = "1.0.0")]
110    pub use super::fs::DirEntryExt;
111    #[doc(no_inline)]
112    #[stable(feature = "file_offset", since = "1.15.0")]
113    pub use super::fs::FileExt;
114    #[doc(no_inline)]
115    #[stable(feature = "rust1", since = "1.0.0")]
116    pub use super::fs::{FileTypeExt, MetadataExt, OpenOptionsExt, PermissionsExt};
117    #[doc(no_inline)]
118    #[stable(feature = "rust1", since = "1.0.0")]
119    pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
120    #[doc(no_inline)]
121    #[unstable(feature = "unix_send_signal", issue = "141975")]
122    pub use super::process::ChildExt;
123    #[doc(no_inline)]
124    #[stable(feature = "rust1", since = "1.0.0")]
125    pub use super::process::{CommandExt, ExitStatusExt};
126    #[doc(no_inline)]
127    #[stable(feature = "rust1", since = "1.0.0")]
128    pub use super::thread::JoinHandleExt;
129}