bump_scope/features/
allocator_api2_03.rs1use allocator_api2_03::alloc::{AllocError, Allocator};
2
3#[cfg(feature = "alloc")]
4use allocator_api2_03::{alloc::Global, boxed::Box};
5
6use crate::{
7 BaseAllocator, Bump, BumpScope, WithoutDealloc, WithoutShrink, alloc::AllocError as CrateAllocError,
8 settings::BumpAllocatorSettings, traits::BumpAllocatorCore,
9};
10
11#[cfg(feature = "alloc")]
12use crate::alloc::{BoxLike, box_like};
13
14use super::allocator_util::{allocator_compat_wrapper, impl_allocator_via_allocator};
15
16allocator_compat_wrapper! {
17 struct AllocatorApi2V03Compat for allocator_api2_03
53}
54
55impl_allocator_via_allocator! {
56 self;
57
58 #[cfg(feature = "alloc")]
59 use {self} for crate as allocator_api2_03 impl[] Global
60
61 use {self} for allocator_api2_03 as crate impl[A, S] Bump<A, S>
62 where [
63 A: BaseAllocator<S::GuaranteedAllocated>,
64 S: BumpAllocatorSettings,
65 ]
66
67 use {self} for allocator_api2_03 as crate impl[A, S] BumpScope<'_, A, S>
68 where [
69 A: BaseAllocator<S::GuaranteedAllocated>,
70 S: BumpAllocatorSettings,
71 ]
72
73 use {self} for allocator_api2_03 as crate impl[A, S] &mut Bump<A, S>
74 where [
75 A: BaseAllocator<S::GuaranteedAllocated>,
76 S: BumpAllocatorSettings,
77 ]
78
79 use {self} for allocator_api2_03 as crate impl[A, S] &mut BumpScope<'_, A, S>
80 where [
81 A: BaseAllocator<S::GuaranteedAllocated>,
82 S: BumpAllocatorSettings,
83 ]
84
85 use {self} for allocator_api2_03 as crate impl[A: BumpAllocatorCore] WithoutShrink<A>
86 use {self} for allocator_api2_03 as crate impl[A: BumpAllocatorCore] WithoutDealloc<A>
87}
88
89impl From<AllocError> for CrateAllocError {
90 #[inline(always)]
91 fn from(_: AllocError) -> Self {
92 CrateAllocError
93 }
94}
95
96impl From<CrateAllocError> for AllocError {
97 #[inline(always)]
98 fn from(_: CrateAllocError) -> Self {
99 AllocError
100 }
101}
102
103#[cfg(feature = "alloc")]
104impl<T: ?Sized, A: Allocator> box_like::Sealed for Box<T, A> {
105 type T = T;
106 type A = A;
107
108 #[inline(always)]
109 unsafe fn from_raw_in(ptr: *mut Self::T, allocator: Self::A) -> Self {
110 unsafe { Box::from_raw_in(ptr, allocator) }
111 }
112}
113
114#[cfg(feature = "alloc")]
115impl<T: ?Sized, A: Allocator> BoxLike for Box<T, A> {}