bump_scope/features/
allocator_api2_02.rs1#[cfg(not(feature = "nightly-allocator-api"))]
2use allocator_api2_02::alloc::{AllocError, Allocator};
3
4#[cfg(feature = "alloc")]
5#[cfg(not(feature = "nightly-allocator-api"))]
6use allocator_api2_02::boxed::Box;
7
8#[cfg(any(test, all(feature = "alloc", not(feature = "nightly-allocator-api"))))]
9use allocator_api2_02::alloc::Global;
10
11#[cfg(not(feature = "nightly-allocator-api"))]
12use crate::{
13 BaseAllocator, Bump, BumpScope, WithoutDealloc, WithoutShrink, alloc::AllocError as CrateAllocError,
14 settings::BumpAllocatorSettings, traits::BumpAllocatorCore,
15};
16
17#[cfg(feature = "alloc")]
18#[cfg(not(feature = "nightly-allocator-api"))]
19use crate::alloc::{BoxLike, box_like};
20
21use super::allocator_util::{allocator_compat_wrapper, impl_allocator_via_allocator};
22
23allocator_compat_wrapper! {
24 struct AllocatorApi2V02Compat for allocator_api2_02
60}
61
62#[cfg(not(feature = "nightly-allocator-api"))]
63impl_allocator_via_allocator! {
64 self;
65
66 #[cfg(feature = "alloc")]
67 use {self} for crate as allocator_api2_02 impl[] Global
68
69 use {self} for allocator_api2_02 as crate impl[A, S] Bump<A, S>
70 where [
71 A: BaseAllocator<S::GuaranteedAllocated>,
72 S: BumpAllocatorSettings,
73 ]
74
75 use {self} for allocator_api2_02 as crate impl[A, S] BumpScope<'_, A, S>
76 where [
77 A: BaseAllocator<S::GuaranteedAllocated>,
78 S: BumpAllocatorSettings,
79 ]
80
81 use {self} for allocator_api2_02 as crate impl[A, S] &mut Bump<A, S>
82 where [
83 A: BaseAllocator<S::GuaranteedAllocated>,
84 S: BumpAllocatorSettings,
85 ]
86
87 use {self} for allocator_api2_02 as crate impl[A, S] &mut BumpScope<'_, A, S>
88 where [
89 A: BaseAllocator<S::GuaranteedAllocated>,
90 S: BumpAllocatorSettings,
91 ]
92
93 use {self} for allocator_api2_02 as crate impl[A: BumpAllocatorCore] WithoutShrink<A>
94 use {self} for allocator_api2_02 as crate impl[A: BumpAllocatorCore] WithoutDealloc<A>
95}
96
97#[cfg(not(feature = "nightly-allocator-api"))]
98impl From<AllocError> for CrateAllocError {
99 #[inline(always)]
100 fn from(_: AllocError) -> Self {
101 CrateAllocError
102 }
103}
104
105#[cfg(not(feature = "nightly-allocator-api"))]
106impl From<CrateAllocError> for AllocError {
107 #[inline(always)]
108 fn from(_: CrateAllocError) -> Self {
109 AllocError
110 }
111}
112
113#[cfg(feature = "alloc")]
114#[cfg(not(feature = "nightly-allocator-api"))]
115impl<T: ?Sized, A: Allocator> box_like::Sealed for Box<T, A> {
116 type T = T;
117 type A = A;
118
119 unsafe fn from_raw_in(ptr: *mut Self::T, allocator: Self::A) -> Self {
120 unsafe { Box::from_raw_in(ptr, allocator) }
121 }
122}
123
124#[cfg(feature = "alloc")]
125#[cfg(not(feature = "nightly-allocator-api"))]
126impl<T: ?Sized, A: Allocator> BoxLike for Box<T, A> {}