use crate::*;
use crate::meta::*;
use super::ffi;
use core::alloc::Layout;
use core::ffi::c_char;
use core::marker::PhantomData;
use core::ptr::NonNull;
#[doc = include_str!("_refs.md")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct StdAllocator<T>(PhantomData<fn(usize) -> T>);
impl<T> StdAllocator<T> {
#[doc = include_str!("_refs.md")]
pub const fn new() -> Self { Self(PhantomData) }
}
impl<T> Meta for StdAllocator<T> {
type Error = ();
const MAX_ALIGN : Alignment = Alignment::of::<T>(); const MAX_SIZE : usize = usize::MAX; const ZST_SUPPORTED : bool = false; }
#[doc = include_str!("_refs.md")]
unsafe impl Stateless for StdAllocator<c_char> {}
#[doc = include_str!("_refs.md")]
unsafe impl thin::Alloc for StdAllocator<c_char> {
fn alloc_uninit(&self, size: usize) -> Result<AllocNN, Self::Error> {
NonNull::new(unsafe { ffi::std_allocator_char_allocate(size) }.cast()).ok_or(())
}
}
#[doc = include_str!("_refs.md")]
#[allow(clippy::missing_safety_doc)]
unsafe impl fat::Free for StdAllocator<c_char> {
unsafe fn free(&self, ptr: AllocNN, layout: Layout) {
unsafe { ffi::std_allocator_char_deallocate(ptr.as_ptr().cast(), layout.size()) }
}
}
unsafe impl fat::Realloc for StdAllocator<c_char> {}
#[no_implicit_prelude] mod cleanroom {
use super::{impls, StdAllocator, c_char};
impls! {
unsafe impl ialloc::fat::Alloc for StdAllocator<c_char> => ialloc::thin::Alloc;
}
}
#[test] fn thin_zst_support() { thin::test::zst_supported_conservative_leak(StdAllocator::<c_char>::new()) }
#[test] fn fat_alignment() { fat::test::alignment(StdAllocator::<c_char>::new()) }
#[test] fn fat_edge_case_sizes() { fat::test::edge_case_sizes(StdAllocator::<c_char>::new()) }
#[test] fn fat_uninit() { if !allocator::cpp::OPERATOR_NEW_ZERO_INITS { unsafe { fat::test::uninit_alloc_unsound(StdAllocator::<c_char>::new()) } } }
#[test] fn fat_uninit_realloc() { fat::test::uninit_realloc(StdAllocator::<c_char>::new()) }
#[test] fn fat_zeroed() { fat::test::zeroed_alloc(StdAllocator::<c_char>::new()) }
#[test] fn fat_zeroed_realloc() { fat::test::zeroed_realloc(StdAllocator::<c_char>::new()) }
#[test] fn fat_zst_support() { fat::test::zst_supported_conservative(StdAllocator::<c_char>::new()) }