use core::ptr::NonNull;
use allocator_api2::alloc::Allocator;
use super::Arena;
use crate::internal::shared_chunk::SharedChunk;
use crate::internal::uninit::{Uninit, UninitDrop};
impl<A: Allocator + Clone> Arena<A> {
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_local<T>(&self) -> Option<Uninit<'_, T>> {
let ticket = self.current_local().try_alloc_uninit::<T>()?;
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_local_with_drop<T>(&self) -> Option<UninitDrop<'_, T>> {
let ticket = self.current_local().try_alloc_uninit_with_drop::<T>()?;
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_local_slice<T>(&self, len: usize) -> Option<Uninit<'_, [T]>> {
let ticket = self.current_local().try_alloc_uninit_slice::<T>(len)?;
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_local_bytes(&self, len: usize) -> Option<Uninit<'_, [u8]>> {
let ticket = self.current_local().try_alloc_bytes(len)?;
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_local_slice_with_drop<T>(&self, len: usize) -> Option<UninitDrop<'_, [T]>> {
let ticket = self.current_local().try_alloc_uninit_slice_with_drop::<T>(len)?;
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_shared<T>(&self) -> Option<(Uninit<'_, T>, NonNull<SharedChunk<A>>)> {
let mutator = self.current_shared();
let ticket = mutator.try_alloc_uninit::<T>()?;
Some(unsafe { (ticket.rebind(), mutator.chunk_ptr_unchecked()) })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_shared_with_drop<T>(&self) -> Option<(UninitDrop<'_, T>, NonNull<SharedChunk<A>>)> {
let mutator = self.current_shared();
let ticket = mutator.try_alloc_uninit_with_drop::<T>()?;
Some(unsafe { (ticket.rebind(), mutator.chunk_ptr_unchecked()) })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] #[allow(
clippy::type_complexity,
reason = "ticket + chunk-ptr tuple is the natural shape; type alias would obscure rather than clarify"
)]
pub(crate) fn try_reserve_shared_slice<T>(&self, len: usize) -> Option<(Uninit<'_, [T]>, NonNull<SharedChunk<A>>)> {
let mutator = self.current_shared();
let ticket = mutator.try_alloc_uninit_slice_prefixed::<T>(len)?;
Some(unsafe { (ticket.rebind(), mutator.chunk_ptr_unchecked()) })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] #[allow(
clippy::type_complexity,
reason = "ticket + chunk-ptr tuple is the natural shape; type alias would obscure rather than clarify"
)]
pub(crate) fn try_reserve_shared_slice_with_drop<T>(&self, len: usize) -> Option<(UninitDrop<'_, [T]>, NonNull<SharedChunk<A>>)> {
let mutator = self.current_shared();
let ticket = mutator.try_alloc_uninit_slice_with_drop_prefixed::<T>(len)?;
Some(unsafe { (ticket.rebind(), mutator.chunk_ptr_unchecked()) })
}
}