2016-09-30 23:56:28 +00:00
|
|
|
//! Platform-independent platform abstraction
|
|
|
|
//!
|
2016-11-10 05:15:56 +02:00
|
|
|
//! This is the platform-independent portion of the standard library's
|
2016-09-30 23:56:28 +00:00
|
|
|
//! platform abstraction layer, whereas `std::sys` is the
|
|
|
|
//! platform-specific portion.
|
|
|
|
//!
|
|
|
|
//! The relationship between `std::sys_common`, `std::sys` and the
|
|
|
|
//! rest of `std` is complex, with dependencies going in all
|
|
|
|
//! directions: `std` depending on `sys_common`, `sys_common`
|
|
|
|
//! depending on `sys`, and `sys` depending on `sys_common` and `std`.
|
2021-04-14 14:03:00 +02:00
|
|
|
//! This is because `sys_common` not only contains platform-independent code,
|
|
|
|
//! but also code that is shared between the different platforms in `sys`.
|
|
|
|
//! Ideally all that shared code should be moved to `sys::common`,
|
|
|
|
//! and the dependencies between `std`, `sys_common` and `sys` all would form a dag.
|
|
|
|
//! Progress on this is tracked in #84187.
|
2016-09-30 23:56:28 +00:00
|
|
|
|
2014-11-09 13:59:23 +01:00
|
|
|
#![allow(missing_docs)]
|
2016-12-20 12:18:55 -08:00
|
|
|
#![allow(missing_debug_implementations)]
|
2014-09-30 17:03:56 -07:00
|
|
|
|
2020-08-27 13:45:01 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2014-11-23 19:21:17 -08:00
|
|
|
pub mod backtrace;
|
2019-03-29 15:57:14 -07:00
|
|
|
pub mod fs;
|
2015-09-08 15:53:46 -07:00
|
|
|
pub mod io;
|
2022-06-03 17:04:14 +02:00
|
|
|
pub mod lazy_box;
|
2021-05-14 03:54:46 +02:00
|
|
|
pub mod memchr;
|
2022-09-04 18:47:59 +02:00
|
|
|
pub mod once;
|
2017-12-17 15:21:47 +00:00
|
|
|
pub mod process;
|
2014-11-23 19:21:17 -08:00
|
|
|
pub mod thread;
|
2014-12-06 18:34:37 -08:00
|
|
|
pub mod thread_info;
|
2020-07-12 11:37:11 +02:00
|
|
|
pub mod thread_local_dtor;
|
2020-09-27 12:27:27 +02:00
|
|
|
pub mod thread_parker;
|
2022-11-08 23:23:08 +05:30
|
|
|
pub mod wstr;
|
2015-01-21 15:55:31 -08:00
|
|
|
pub mod wtf8;
|
2014-09-30 17:03:56 -07:00
|
|
|
|
2022-10-08 20:19:21 +02:00
|
|
|
cfg_if::cfg_if! {
|
|
|
|
if #[cfg(target_os = "windows")] {
|
|
|
|
pub use crate::sys::thread_local_key;
|
|
|
|
} else {
|
|
|
|
pub mod thread_local_key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-10 08:12:14 -07:00
|
|
|
cfg_if::cfg_if! {
|
2020-10-27 13:10:31 +00:00
|
|
|
if #[cfg(any(target_os = "l4re",
|
2019-10-06 15:26:14 +00:00
|
|
|
target_os = "hermit",
|
2020-05-31 18:09:25 -07:00
|
|
|
feature = "restricted-std",
|
2021-10-28 16:28:21 -07:00
|
|
|
all(target_family = "wasm", not(target_os = "emscripten")),
|
2018-12-31 15:45:42 -08:00
|
|
|
all(target_vendor = "fortanix", target_env = "sgx")))] {
|
2019-02-11 04:23:21 +09:00
|
|
|
pub use crate::sys::net;
|
2017-10-22 20:01:00 -07:00
|
|
|
} else {
|
|
|
|
pub mod net;
|
|
|
|
}
|
|
|
|
}
|
2016-10-27 20:57:49 -06:00
|
|
|
|
2014-09-30 17:03:56 -07:00
|
|
|
// common error constructors
|
|
|
|
|
2015-01-21 15:55:31 -08:00
|
|
|
/// A trait for viewing representations from std types
|
2015-02-02 21:39:14 -08:00
|
|
|
#[doc(hidden)]
|
2015-01-21 15:55:31 -08:00
|
|
|
pub trait AsInner<Inner: ?Sized> {
|
2014-11-20 18:26:47 -08:00
|
|
|
fn as_inner(&self) -> &Inner;
|
2014-09-30 17:03:56 -07:00
|
|
|
}
|
|
|
|
|
2015-02-02 21:39:14 -08:00
|
|
|
/// A trait for viewing representations from std types
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub trait AsInnerMut<Inner: ?Sized> {
|
|
|
|
fn as_inner_mut(&mut self) -> &mut Inner;
|
|
|
|
}
|
|
|
|
|
2015-01-21 15:55:31 -08:00
|
|
|
/// A trait for extracting representations from std types
|
2015-02-02 21:39:14 -08:00
|
|
|
#[doc(hidden)]
|
2015-01-21 15:55:31 -08:00
|
|
|
pub trait IntoInner<Inner> {
|
|
|
|
fn into_inner(self) -> Inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A trait for creating std types from internal representations
|
2015-02-02 21:39:14 -08:00
|
|
|
#[doc(hidden)]
|
2015-01-21 15:55:31 -08:00
|
|
|
pub trait FromInner<Inner> {
|
|
|
|
fn from_inner(inner: Inner) -> Self;
|
|
|
|
}
|
2015-09-08 15:53:46 -07:00
|
|
|
|
2015-11-16 17:36:14 -08:00
|
|
|
// Computes (value*numer)/denom without overflow, as long as both
|
|
|
|
// (numer*denom) and the overall result fit into i64 (which is the case
|
|
|
|
// for our time conversions).
|
|
|
|
#[allow(dead_code)] // not used on all platforms
|
|
|
|
pub fn mul_div_u64(value: u64, numer: u64, denom: u64) -> u64 {
|
|
|
|
let q = value / denom;
|
|
|
|
let r = value % denom;
|
|
|
|
// Decompose value as (value/denom*denom + value%denom),
|
|
|
|
// substitute into (value*numer)/denom and simplify.
|
|
|
|
// r < denom, so (denom*numer) is the upper bound of (r*numer)
|
|
|
|
q * numer + r * numer / denom
|
|
|
|
}
|