attachable-slab-allocator 0.1.0

A high-performance, $O(1)$, Master-Slave slab allocator designed for `no_std` environments, kernels, and embedded systems. This library provides fixed-size memory management with RAII safety while remaining completely agnostic of the underlying memory provider.
Documentation
//! # The Lock Interface
//!
//! This module defines the contract for synchronization primitives used by the Slab Allocator.
//! By using a trait, the allocator remains agnostic of the environment, allowing it to work
//! in single-threaded systems, multi-threaded applications, or even interrupt-driven kernels.
//!
//! ## Implementing Your Own Lock
//!
//! If the provided [`SpinLock`] or [`NoLock`] do not fit your needs, you can implement
//! [`LockTrait`] for your own type.
//!
//! ### THE 16-BYTE RULE
//! To keep the `Slab` header compact and minimize internal fragmentation, any type
//! implementing `LockTrait` **MUST NOT exceed 16 bytes** in size. This is enforced
//! via a `static_assert` within the `Slab` struct.
//!
//! If your lock needs more state, consider storing a pointer to an external structure.

pub trait LockTrait {
    /// An RAII guard returned by the `lock` method.
    ///
    /// When this guard is dropped, the lock must be automatically released.
    type Guard<'a>
    where
        Self: 'a;

    /// Acquires the lock, blocking the current thread/context until available.
    ///
    /// Returns a [`Guard`] that releases the lock upon being dropped.
    fn lock(&self) -> Self::Guard<'_>;

    /// Initializes a new instance of the lock.
    ///
    /// This is called when a new Master Slab is allocated.
    fn init() -> Self;
}