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 Bump, BumpScope, WithoutDealloc, WithoutShrink,
8 alloc::{AllocError as CrateAllocError, Allocator as CrateAllocator, 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
49}
50
51impl_allocator_via_allocator! {
52 self;
53
54 #[cfg(feature = "alloc")]
55 use {self} for crate as core impl[] Global
56
57 use {self} for core as crate impl[A, S] Bump<A, S>
58 where [
59 A: CrateAllocator,
60 S: BumpAllocatorSettings,
61 ]
62
63 use {self} for core as crate impl[A, S] BumpScope<'_, A, S>
64 where [
65 A: CrateAllocator,
66 S: BumpAllocatorSettings,
67 ]
68
69 use {self} for core as crate impl[A: BumpAllocatorCore] WithoutShrink<A>
70 use {self} for core as crate impl[A: BumpAllocatorCore] WithoutDealloc<A>
71}
72
73impl From<AllocError> for CrateAllocError {
74 #[inline(always)]
75 fn from(_: AllocError) -> Self {
76 CrateAllocError
77 }
78}
79
80impl From<CrateAllocError> for AllocError {
81 #[inline(always)]
82 fn from(_: CrateAllocError) -> Self {
83 AllocError
84 }
85}
86
87impl<T: ?Sized, A: Allocator> box_like::Sealed for Box<T, A> {
88 type T = T;
89 type A = A;
90
91 #[inline(always)]
92 unsafe fn from_raw_in(ptr: *mut Self::T, allocator: Self::A) -> Self {
93 unsafe { Box::from_raw_in(ptr, allocator) }
94 }
95}
96
97impl<T: ?Sized, A: Allocator> BoxLike for Box<T, A> {}