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