1 //! Platform-independent platform abstraction
3 //! This is the platform-independent portion of the standard library's
4 //! platform abstraction layer, whereas `std::sys` is the
5 //! platform-specific portion.
7 //! The relationship between `std::sys_common`, `std::sys` and the
8 //! rest of `std` is complex, with dependencies going in all
9 //! directions: `std` depending on `sys_common`, `sys_common`
10 //! depending on `sys`, and `sys` depending on `sys_common` and `std`.
11 //! This is because `sys_common` not only contains platform-independent code,
12 //! but also code that is shared between the different platforms in `sys`.
13 //! Ideally all that shared code should be moved to `sys::common`,
14 //! and the dependencies between `std`, `sys_common` and `sys` all would form a dag.
15 //! Progress on this is tracked in #84187.
17 #![allow(missing_docs)]
18 #![allow(missing_debug_implementations)]
33 pub mod thread_local_dtor;
34 pub mod thread_parker;
38 if #[cfg(target_os = "windows")] {
39 pub use crate::sys::thread_local_key;
41 pub mod thread_local_key;
46 if #[cfg(any(target_os = "l4re",
48 feature = "restricted-std",
49 all(target_family = "wasm", not(target_os = "emscripten")),
50 all(target_vendor = "fortanix", target_env = "sgx")))] {
51 pub use crate::sys::net;
57 // common error constructors
59 /// A trait for viewing representations from std types
61 pub trait AsInner<Inner: ?Sized> {
62 fn as_inner(&self) -> &Inner;
65 /// A trait for viewing representations from std types
67 pub trait AsInnerMut<Inner: ?Sized> {
68 fn as_inner_mut(&mut self) -> &mut Inner;
71 /// A trait for extracting representations from std types
73 pub trait IntoInner<Inner> {
74 fn into_inner(self) -> Inner;
77 /// A trait for creating std types from internal representations
79 pub trait FromInner<Inner> {
80 fn from_inner(inner: Inner) -> Self;
83 // Computes (value*numer)/denom without overflow, as long as both
84 // (numer*denom) and the overall result fit into i64 (which is the case
85 // for our time conversions).
86 #[allow(dead_code)] // not used on all platforms
87 pub fn mul_div_u64(value: u64, numer: u64, denom: u64) -> u64 {
88 let q = value / denom;
89 let r = value % denom;
90 // Decompose value as (value/denom*denom + value%denom),
91 // substitute into (value*numer)/denom and simplify.
92 // r < denom, so (denom*numer) is the upper bound of (r*numer)
93 q * numer + r * numer / denom