]> git.lizzy.rs Git - rust.git/blob - library/std/src/os/unix/mod.rs
Rollup merge of #99454 - benluelo:control-flow/continue-combinators, r=scottmcm
[rust.git] / library / std / src / 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)]
36 use crate::os::linux as platform;
37
38 #[cfg(not(doc))]
39 mod platform {
40     #[cfg(target_os = "android")]
41     pub use crate::os::android::*;
42     #[cfg(target_os = "dragonfly")]
43     pub use crate::os::dragonfly::*;
44     #[cfg(target_os = "emscripten")]
45     pub use crate::os::emscripten::*;
46     #[cfg(target_os = "espidf")]
47     pub use crate::os::espidf::*;
48     #[cfg(target_os = "freebsd")]
49     pub use crate::os::freebsd::*;
50     #[cfg(target_os = "fuchsia")]
51     pub use crate::os::fuchsia::*;
52     #[cfg(target_os = "haiku")]
53     pub use crate::os::haiku::*;
54     #[cfg(target_os = "horizon")]
55     pub use crate::os::horizon::*;
56     #[cfg(target_os = "illumos")]
57     pub use crate::os::illumos::*;
58     #[cfg(target_os = "ios")]
59     pub use crate::os::ios::*;
60     #[cfg(target_os = "l4re")]
61     pub use crate::os::l4re::*;
62     #[cfg(target_os = "linux")]
63     pub use crate::os::linux::*;
64     #[cfg(target_os = "macos")]
65     pub use crate::os::macos::*;
66     #[cfg(target_os = "netbsd")]
67     pub use crate::os::netbsd::*;
68     #[cfg(target_os = "openbsd")]
69     pub use crate::os::openbsd::*;
70     #[cfg(target_os = "redox")]
71     pub use crate::os::redox::*;
72     #[cfg(target_os = "solaris")]
73     pub use crate::os::solaris::*;
74     #[cfg(target_os = "vxworks")]
75     pub use crate::os::vxworks::*;
76 }
77
78 pub mod ffi;
79 pub mod fs;
80 pub mod io;
81 pub mod net;
82 pub mod process;
83 pub mod raw;
84 pub mod thread;
85
86 #[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
87 #[cfg(any(
88     target_os = "android",
89     target_os = "linux",
90     target_os = "dragonfly",
91     target_os = "freebsd",
92     target_os = "ios",
93     target_os = "watchos",
94     target_os = "macos",
95     target_os = "netbsd",
96     target_os = "openbsd"
97 ))]
98 pub mod ucred;
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")]
104 pub 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     #[stable(feature = "rust1", since = "1.0.0")]
122     pub use super::process::{CommandExt, ExitStatusExt};
123     #[doc(no_inline)]
124     #[stable(feature = "rust1", since = "1.0.0")]
125     pub use super::thread::JoinHandleExt;
126 }