bump_scope/features/
allocator_api2_04.rs1use allocator_api2_04::alloc::{AllocError, Allocator};
2
3#[cfg(feature = "alloc")]
4use allocator_api2_04::{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 AllocatorApi2V04Compat for allocator_api2_04
53}
54
55impl_allocator_via_allocator! {
56 self;
57
58 #[cfg(feature = "alloc")]
59 use {self} for crate as allocator_api2_04 impl[] Global
60
61 use {self} for allocator_api2_04 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_04 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_04 as crate impl[A: BumpAllocatorCore] WithoutShrink<A>
74 use {self} for allocator_api2_04 as crate impl[A: BumpAllocatorCore] WithoutDealloc<A>
75}
76
77impl From<AllocError> for CrateAllocError {
78 #[inline(always)]
79 fn from(_: AllocError) -> Self {
80 CrateAllocError
81 }
82}
83
84impl From<CrateAllocError> for AllocError {
85 #[inline(always)]
86 fn from(_: CrateAllocError) -> Self {
87 AllocError
88 }
89}
90
91#[cfg(feature = "alloc")]
92impl<T: ?Sized, A: Allocator> box_like::Sealed for Box<T, A> {
93 type T = T;
94 type A = A;
95
96 #[inline(always)]
97 unsafe fn from_raw_in(ptr: *mut Self::T, allocator: Self::A) -> Self {
98 unsafe { Box::from_raw_in(ptr, allocator) }
99 }
100}
101
102#[cfg(feature = "alloc")]
103impl<T: ?Sized, A: Allocator> BoxLike for Box<T, A> {}