]> git.lizzy.rs Git - rust.git/blob - library/std/src/os/unix/mod.rs
Auto merge of #86492 - hyd-dev:no-mangle-method, r=petrochenkov
[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 #![stable(feature = "rust1", since = "1.0.0")]
29 #![doc(cfg(unix))]
30
31 // Use linux as the default platform when documenting on other platforms like Windows
32 #[cfg(doc)]
33 use crate::os::linux as platform;
34
35 #[cfg(not(doc))]
36 mod platform {
37     #[cfg(target_os = "android")]
38     pub use crate::os::android::*;
39     #[cfg(target_os = "dragonfly")]
40     pub use crate::os::dragonfly::*;
41     #[cfg(target_os = "emscripten")]
42     pub use crate::os::emscripten::*;
43     #[cfg(target_os = "espidf")]
44     pub use crate::os::espidf::*;
45     #[cfg(target_os = "freebsd")]
46     pub use crate::os::freebsd::*;
47     #[cfg(target_os = "fuchsia")]
48     pub use crate::os::fuchsia::*;
49     #[cfg(target_os = "haiku")]
50     pub use crate::os::haiku::*;
51     #[cfg(target_os = "illumos")]
52     pub use crate::os::illumos::*;
53     #[cfg(target_os = "ios")]
54     pub use crate::os::ios::*;
55     #[cfg(any(target_os = "linux", target_os = "l4re"))]
56     pub use crate::os::linux::*;
57     #[cfg(target_os = "macos")]
58     pub use crate::os::macos::*;
59     #[cfg(target_os = "netbsd")]
60     pub use crate::os::netbsd::*;
61     #[cfg(target_os = "openbsd")]
62     pub use crate::os::openbsd::*;
63     #[cfg(target_os = "redox")]
64     pub use crate::os::redox::*;
65     #[cfg(target_os = "solaris")]
66     pub use crate::os::solaris::*;
67     #[cfg(target_os = "vxworks")]
68     pub use crate::os::vxworks::*;
69 }
70
71 pub mod ffi;
72 pub mod fs;
73 pub mod io;
74 pub mod net;
75 pub mod process;
76 pub mod raw;
77 pub mod thread;
78
79 #[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
80 #[cfg(any(
81     target_os = "android",
82     target_os = "linux",
83     target_os = "dragonfly",
84     target_os = "freebsd",
85     target_os = "ios",
86     target_os = "macos",
87     target_os = "netbsd",
88     target_os = "openbsd"
89 ))]
90 pub mod ucred;
91
92 /// A prelude for conveniently writing platform-specific code.
93 ///
94 /// Includes all extension traits, and some important type definitions.
95 #[stable(feature = "rust1", since = "1.0.0")]
96 pub mod prelude {
97     #[doc(no_inline)]
98     #[stable(feature = "rust1", since = "1.0.0")]
99     pub use super::ffi::{OsStrExt, OsStringExt};
100     #[doc(no_inline)]
101     #[stable(feature = "rust1", since = "1.0.0")]
102     pub use super::fs::DirEntryExt;
103     #[doc(no_inline)]
104     #[stable(feature = "file_offset", since = "1.15.0")]
105     pub use super::fs::FileExt;
106     #[doc(no_inline)]
107     #[stable(feature = "rust1", since = "1.0.0")]
108     pub use super::fs::{FileTypeExt, MetadataExt, OpenOptionsExt, PermissionsExt};
109     #[doc(no_inline)]
110     #[stable(feature = "rust1", since = "1.0.0")]
111     pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
112     #[doc(no_inline)]
113     #[stable(feature = "rust1", since = "1.0.0")]
114     pub use super::process::{CommandExt, ExitStatusExt};
115     #[doc(no_inline)]
116     #[stable(feature = "rust1", since = "1.0.0")]
117     pub use super::thread::JoinHandleExt;
118 }