]> git.proxmox.com Git - rustc.git/blame - library/std/src/sys_common/mod.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / library / std / src / sys_common / mod.rs
CommitLineData
c30ab7b3
SL
1//! Platform-independent platform abstraction
2//!
476ff2be 3//! This is the platform-independent portion of the standard library's
c30ab7b3
SL
4//! platform abstraction layer, whereas `std::sys` is the
5//! platform-specific portion.
6//!
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`.
cdc7bbd5
XL
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.
c30ab7b3 16
1a4d82fc 17#![allow(missing_docs)]
32a655c1 18#![allow(missing_debug_implementations)]
1a4d82fc 19
1b1a35ee
XL
20#[cfg(test)]
21mod tests;
22
1a4d82fc
JJ
23pub mod backtrace;
24pub mod condvar;
dfeec247 25pub mod fs;
e9174d1e 26pub mod io;
923072b8 27pub mod lazy_box;
17df50a5 28pub mod memchr;
1a4d82fc 29pub mod mutex;
dfeec247 30pub mod process;
9346a6ac 31pub mod remutex;
1a4d82fc 32pub mod rwlock;
1a4d82fc
JJ
33pub mod thread;
34pub mod thread_info;
3dfed10e
XL
35pub mod thread_local_dtor;
36pub mod thread_local_key;
1b1a35ee 37pub mod thread_parker;
85aaf69f 38pub mod wtf8;
1a4d82fc 39
dc9dc135 40cfg_if::cfg_if! {
fc512014 41 if #[cfg(any(target_os = "l4re",
e74abb32 42 target_os = "hermit",
3dfed10e 43 feature = "restricted-std",
3c0e092e 44 all(target_family = "wasm", not(target_os = "emscripten")),
0731742a 45 all(target_vendor = "fortanix", target_env = "sgx")))] {
532ac7d7 46 pub use crate::sys::net;
abe05a73
XL
47 } else {
48 pub mod net;
49 }
50}
476ff2be 51
1a4d82fc
JJ
52// common error constructors
53
85aaf69f
SL
54/// A trait for viewing representations from std types
55#[doc(hidden)]
56pub trait AsInner<Inner: ?Sized> {
1a4d82fc
JJ
57 fn as_inner(&self) -> &Inner;
58}
59
85aaf69f
SL
60/// A trait for viewing representations from std types
61#[doc(hidden)]
62pub trait AsInnerMut<Inner: ?Sized> {
63 fn as_inner_mut(&mut self) -> &mut Inner;
64}
65
66/// A trait for extracting representations from std types
67#[doc(hidden)]
68pub trait IntoInner<Inner> {
69 fn into_inner(self) -> Inner;
70}
71
72/// A trait for creating std types from internal representations
73#[doc(hidden)]
74pub trait FromInner<Inner> {
75 fn from_inner(inner: Inner) -> Self;
76}
e9174d1e 77
92a42be0
SL
78// Computes (value*numer)/denom without overflow, as long as both
79// (numer*denom) and the overall result fit into i64 (which is the case
80// for our time conversions).
81#[allow(dead_code)] // not used on all platforms
82pub fn mul_div_u64(value: u64, numer: u64, denom: u64) -> u64 {
83 let q = value / denom;
84 let r = value % denom;
85 // Decompose value as (value/denom*denom + value%denom),
86 // substitute into (value*numer)/denom and simplify.
87 // r < denom, so (denom*numer) is the upper bound of (r*numer)
88 q * numer + r * numer / denom
89}