allocator_api2/stable/
mod.rs1#![deny(unsafe_op_in_unsafe_fn)]
2#![allow(clippy::needless_doctest_main, clippy::partialeq_ne_impl)]
3
4#[cfg(feature = "alloc")]
5pub use self::slice::SliceExt;
6
7pub mod alloc;
8
9#[cfg(feature = "alloc")]
10pub mod boxed;
11
12#[cfg(feature = "alloc")]
13mod raw_vec;
14
15#[cfg(feature = "alloc")]
16pub mod vec;
17
18#[cfg(feature = "alloc")]
19mod macros;
20
21#[cfg(feature = "alloc")]
22mod slice;
23
24#[cfg(feature = "alloc")]
25mod unique;
26
27#[macro_export]
46#[cfg(feature = "alloc")]
47macro_rules! unsize_box {( $boxed:expr $(,)? ) => ({
48    let (ptr, allocator) = ::allocator_api2::boxed::Box::into_raw_with_allocator($boxed);
49    let ptr: *mut _ = ptr;
55    unsafe {
58        ::allocator_api2::boxed::Box::from_raw_in(ptr, allocator)
59    }
60})}
61
62#[cfg(feature = "alloc")]
63pub mod collections {
64    pub use super::raw_vec::{TryReserveError, TryReserveErrorKind};
65}
66
67#[cfg(feature = "alloc")]
68#[track_caller]
69#[inline(always)]
70#[cfg(debug_assertions)]
71unsafe fn assume(v: bool) {
72    if !v {
73        core::unreachable!()
74    }
75}
76
77#[cfg(feature = "alloc")]
78#[track_caller]
79#[inline(always)]
80#[cfg(not(debug_assertions))]
81unsafe fn assume(v: bool) {
82    if !v {
83        unsafe {
84            core::hint::unreachable_unchecked();
85        }
86    }
87}
88
89#[cfg(feature = "alloc")]
90#[inline(always)]
91fn addr<T>(x: *const T) -> usize {
92    #[allow(clippy::useless_transmute, clippy::transmutes_expressible_as_ptr_casts)]
93    unsafe {
94        core::mem::transmute(x)
95    }
96}
97
98#[cfg(feature = "alloc")]
99#[inline(always)]
100fn invalid_mut<T>(addr: usize) -> *mut T {
101    #[allow(clippy::useless_transmute, clippy::transmutes_expressible_as_ptr_casts)]
102    unsafe {
103        core::mem::transmute(addr)
104    }
105}