#![doc(html_root_url = "https://docs.rs/acid_alloc/0.1.0")]
#![no_std]
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]
#![deny(unsafe_op_in_unsafe_fn)]
#![cfg_attr(feature = "unstable", feature(alloc_layout_extra))]
#![cfg_attr(feature = "unstable", feature(allocator_api))]
#![cfg_attr(feature = "unstable", feature(int_log))]
#![cfg_attr(feature = "unstable", feature(strict_provenance))]
#![cfg_attr(docs_rs, feature(doc_cfg))]
#![allow(unstable_name_collisions)]
#[cfg(test)]
extern crate std;
macro_rules! requires_sptr_or_unstable {
($($it:item)*) => {
$(
#[cfg(any(feature = "sptr", feature = "unstable"))]
$it
)*
};
}
#[cfg(not(any(feature = "sptr", feature = "unstable")))]
compile_error!("At least one of these crate features must be enabled: [\"sptr\", \"unstable\"].");
#[cfg(any(feature = "alloc", test))]
extern crate alloc;
requires_sptr_or_unstable! {
mod base;
mod bitmap;
pub mod buddy;
pub mod bump;
pub mod slab;
#[cfg(test)]
mod tests;
#[cfg(not(feature = "unstable"))]
pub(crate) mod core;
#[cfg(feature = "unstable")]
pub(crate) mod core {
pub use core::{alloc, cmp, fmt, mem, num, ptr, slice, sync};
}
use crate::{
base::{BasePtr, BlockLink, DoubleBlockLink},
core::{
alloc::{Layout},
ptr::NonNull,
},
};
#[cfg(not(feature = "unstable"))]
use crate::core::alloc::LayoutError;
#[cfg(feature = "unstable")]
use crate::core::alloc::Allocator;
#[doc(inline)]
pub use crate::{buddy::Buddy, bump::Bump, core::alloc::AllocError, slab::Slab};
#[cfg(not(feature = "unstable"))]
pub(crate) fn layout_error() -> LayoutError {
Layout::from_size_align(0, 0).unwrap_err()
}
#[derive(Clone, Debug)]
pub enum AllocInitError {
AllocFailed(Layout),
InvalidConfig,
InvalidLocation,
}
pub trait BackingAllocator: Sealed {
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout);
}
#[derive(Clone, Debug)]
pub struct Raw;
impl Sealed for Raw {}
impl BackingAllocator for Raw {
unsafe fn deallocate(&self, _: NonNull<u8>, _: Layout) {}
}
#[cfg(all(any(feature = "alloc", test), not(feature = "unstable")))]
#[derive(Clone, Debug)]
pub struct Global;
#[cfg(all(any(feature = "alloc", test), not(feature = "unstable")))]
impl Sealed for Global {}
#[cfg(all(any(feature = "alloc", test), not(feature = "unstable")))]
impl BackingAllocator for Global {
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
unsafe { alloc::alloc::dealloc(ptr.as_ptr(), layout) };
}
}
#[cfg(all(any(feature = "alloc", test), feature = "unstable"))]
pub use alloc::alloc::Global;
#[cfg(feature = "unstable")]
impl<A: Allocator> Sealed for A {}
#[cfg(feature = "unstable")]
impl<A: Allocator> BackingAllocator for A {
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
unsafe { Allocator::deallocate(self, ptr, layout) };
}
}
#[doc(hidden)]
mod private {
pub trait Sealed {}
}
use private::Sealed;
}