1#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
19#[inline(always)]
20pub const fn u64_from_usize(x: usize) -> u64 {
21 x as u64
22}
23
24#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
25pub const fn usize_from_u32(x: u32) -> usize {
26 x as usize
27}
28
29#[cfg(all(
30 target_arch = "aarch64",
31 target_endian = "little",
32 target_pointer_width = "64"
33))]
34#[allow(clippy::cast_possible_truncation)]
35pub fn usize_from_u64(x: u64) -> usize {
36 x as usize
37}
38
39#[allow(clippy::cast_possible_truncation)]
41#[inline(always)]
42pub const fn usize_from_u64_saturated(x: u64) -> usize {
43 const USIZE_MAX: u64 = u64_from_usize(usize::MAX);
44 if x < USIZE_MAX {
45 x as usize
46 } else {
47 usize::MAX
48 }
49}
50
51#[macro_use]
52mod cold_error;
53
54mod array_flat_map;
55mod array_split_map;
56
57pub mod cstr;
58
59pub mod sliceutil;
60
61#[cfg(feature = "alloc")]
62mod leading_zeros_skipped;
63
64#[cfg(any(
65 all(target_arch = "aarch64", target_endian = "little"),
66 all(target_arch = "arm", target_endian = "little"),
67 target_arch = "x86",
68 target_arch = "x86_64"
69))]
70pub mod once_cell {
71 pub mod race;
72}
73
74mod notsend;
75pub mod ptr;
76
77pub mod slice;
78
79#[cfg(test)]
80mod test;
81
82mod unwrap_const;
83
84pub use self::{
85 array_flat_map::ArrayFlatMap, array_split_map::ArraySplitMap, notsend::NotSend,
86 unwrap_const::unwrap_const,
87};
88
89#[cfg(feature = "alloc")]
90pub use leading_zeros_skipped::LeadingZerosStripped;
91
92#[cfg(test)]
93mod tests {
94 use super::*;
95 #[test]
96 fn test_usize_from_u64_saturated() {
97 const USIZE_MAX: u64 = u64_from_usize(usize::MAX);
98 assert_eq!(usize_from_u64_saturated(u64::MIN), usize::MIN);
99 assert_eq!(usize_from_u64_saturated(USIZE_MAX), usize::MAX);
100 assert_eq!(usize_from_u64_saturated(USIZE_MAX - 1), usize::MAX - 1);
101
102 #[cfg(not(target_pointer_width = "64"))]
103 {
104 assert_eq!(usize_from_u64_saturated(USIZE_MAX + 1), usize::MAX);
105 }
106 }
107}