use super::generic::{GenericBump, IntoLayout};
#[cfg(any(feature = "allocator_api", feature = "allocator-fallback"))]
use super::{AllocError, Allocator};
use alloc::alloc::Layout;
use core::ptr::NonNull;
unsafe impl IntoLayout for Layout {}
pub struct DynamicBump(GenericBump<Layout>);
impl DynamicBump {
pub fn new(layout: Layout) -> Self {
Self(GenericBump::new(layout))
}
pub fn layout(&self) -> Layout {
self.0.layout()
}
pub fn allocate(&self, layout: Layout) -> Option<NonNull<[u8]>> {
self.0.allocate(layout)
}
#[allow(clippy::mut_from_ref)]
#[must_use]
pub fn alloc_value<T>(&self, value: T) -> &mut T {
self.0.alloc_value(value)
}
#[allow(clippy::mut_from_ref)]
pub fn try_alloc_value<T>(&self, value: T) -> Result<&mut T, T> {
self.0.try_alloc_value(value)
}
pub fn can_allocate(&self, layout: Layout) -> bool {
self.0.can_allocate(layout)
}
}
#[cfg(any(feature = "allocator_api", feature = "allocator-fallback"))]
#[cfg_attr(
feature = "doc_cfg",
doc(cfg(any(
feature = "allocator_api",
feature = "allocator-fallback",
)))
)]
unsafe impl Allocator for DynamicBump {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
self.allocate(layout).ok_or(AllocError)
}
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
}
}
#[cfg(doctest)]
mod dynamic_bump_does_not_impl_clone {}