use allocator_api2_03::alloc::{AllocError, Allocator};
#[cfg(feature = "alloc")]
use allocator_api2_03::{alloc::Global, boxed::Box};
use crate::{
BaseAllocator, Bump, BumpScope, WithoutDealloc, WithoutShrink, alloc::AllocError as CrateAllocError,
settings::BumpAllocatorSettings, traits::BumpAllocatorCore,
};
#[cfg(feature = "alloc")]
use crate::alloc::{BoxLike, box_like};
use super::allocator_util::{allocator_compat_wrapper, impl_allocator_via_allocator};
allocator_compat_wrapper! {
struct AllocatorApi2V03Compat for allocator_api2_03
}
impl_allocator_via_allocator! {
self;
#[cfg(feature = "alloc")]
use {self} for crate as allocator_api2_03 impl[] Global
use {self} for allocator_api2_03 as crate impl[A, S] Bump<A, S>
where [
A: BaseAllocator<S::GuaranteedAllocated>,
S: BumpAllocatorSettings,
]
use {self} for allocator_api2_03 as crate impl[A, S] BumpScope<'_, A, S>
where [
A: BaseAllocator<S::GuaranteedAllocated>,
S: BumpAllocatorSettings,
]
use {self} for allocator_api2_03 as crate impl[A, S] &mut Bump<A, S>
where [
A: BaseAllocator<S::GuaranteedAllocated>,
S: BumpAllocatorSettings,
]
use {self} for allocator_api2_03 as crate impl[A, S] &mut BumpScope<'_, A, S>
where [
A: BaseAllocator<S::GuaranteedAllocated>,
S: BumpAllocatorSettings,
]
use {self} for allocator_api2_03 as crate impl[A: BumpAllocatorCore] WithoutShrink<A>
use {self} for allocator_api2_03 as crate impl[A: BumpAllocatorCore] WithoutDealloc<A>
}
impl From<AllocError> for CrateAllocError {
#[inline(always)]
fn from(_: AllocError) -> Self {
CrateAllocError
}
}
impl From<CrateAllocError> for AllocError {
#[inline(always)]
fn from(_: CrateAllocError) -> Self {
AllocError
}
}
#[cfg(feature = "alloc")]
impl<T: ?Sized, A: Allocator> box_like::Sealed for Box<T, A> {
type T = T;
type A = A;
#[inline(always)]
unsafe fn from_raw_in(ptr: *mut Self::T, allocator: Self::A) -> Self {
unsafe { Box::from_raw_in(ptr, allocator) }
}
}
#[cfg(feature = "alloc")]
impl<T: ?Sized, A: Allocator> BoxLike for Box<T, A> {}