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