xref: /drstd/src/std/os/unix/mod.rs (revision 0fe3ff0054d3aec7fbf9bddecfecb10bc7d23a51)
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::std::ffi::OsStr
29 //! [`OsString`]: crate::std::ffi::OsString
30 
31 #![doc(cfg(unix))]
32 
33 // Use linux as the default platform when documenting on other platforms like Windows
34 #[cfg(doc)]
35 use crate::std::os::linux as platform;
36 
37 #[cfg(not(doc))]
38 mod platform {
39     #[cfg(target_os = "android")]
40     pub use crate::std::os::android::*;
41     #[cfg(target_os = "dragonfly")]
42     pub use crate::std::os::dragonfly::*;
43     #[cfg(target_os = "emscripten")]
44     pub use crate::std::os::emscripten::*;
45     #[cfg(target_os = "espidf")]
46     pub use crate::std::os::espidf::*;
47     #[cfg(target_os = "freebsd")]
48     pub use crate::std::os::freebsd::*;
49     #[cfg(target_os = "fuchsia")]
50     pub use crate::std::os::fuchsia::*;
51     #[cfg(target_os = "haiku")]
52     pub use crate::std::os::haiku::*;
53     #[cfg(target_os = "horizon")]
54     pub use crate::std::os::horizon::*;
55     #[cfg(target_os = "illumos")]
56     pub use crate::std::os::illumos::*;
57     #[cfg(target_os = "ios")]
58     pub use crate::std::os::ios::*;
59     #[cfg(target_os = "l4re")]
60     pub use crate::std::os::l4re::*;
61     #[cfg(target_os = "linux")]
62     pub use crate::std::os::linux::*;
63     #[cfg(target_os = "dragonos")]
64     pub use crate::std::os::linux::*;
65     #[cfg(target_os = "macos")]
66     pub use crate::std::os::macos::*;
67     #[cfg(target_os = "netbsd")]
68     pub use crate::std::os::netbsd::*;
69     #[cfg(target_os = "nto")]
70     pub use crate::std::os::nto::*;
71     #[cfg(target_os = "openbsd")]
72     pub use crate::std::os::openbsd::*;
73     #[cfg(target_os = "redox")]
74     pub use crate::std::os::redox::*;
75     #[cfg(target_os = "solaris")]
76     pub use crate::std::os::solaris::*;
77     #[cfg(target_os = "tvos")]
78     pub use crate::std::os::tvos::*;
79     #[cfg(target_os = "vita")]
80     pub use crate::std::os::vita::*;
81     #[cfg(target_os = "vxworks")]
82     pub use crate::std::os::vxworks::*;
83     #[cfg(target_os = "watchos")]
84     pub use crate::std::os::watchos::*;
85 }
86 
87 pub mod ffi;
88 pub mod fs;
89 pub mod io;
90 pub mod net;
91 pub mod process;
92 pub mod raw;
93 pub mod thread;
94 
95 #[cfg(any(
96     target_os = "android",
97     target_os = "linux",
98     target_os = "dragonfly",
99     target_os = "freebsd",
100     target_os = "ios",
101     target_os = "tvos",
102     target_os = "watchos",
103     target_os = "macos",
104     target_os = "netbsd",
105     target_os = "openbsd",
106     target_os = "nto",
107     target_os = "dragonos"
108 ))]
109 pub mod ucred;
110 
111 /// A prelude for conveniently writing platform-specific code.
112 ///
113 /// Includes all extension traits, and some important type definitions.
114 pub mod prelude {
115     #[doc(no_inline)]
116     pub use super::ffi::{OsStrExt, OsStringExt};
117     #[doc(no_inline)]
118     pub use super::fs::DirEntryExt;
119     #[doc(no_inline)]
120     pub use super::fs::FileExt;
121     #[doc(no_inline)]
122     pub use super::fs::{FileTypeExt, MetadataExt, OpenOptionsExt, PermissionsExt};
123     #[doc(no_inline)]
124     pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
125     #[doc(no_inline)]
126     pub use super::process::{CommandExt, ExitStatusExt};
127     #[doc(no_inline)]
128     pub use super::thread::JoinHandleExt;
129 }
130