realloc 0.1.0

A re-implementation of various ::alloc features
Documentation
use core::sync::atomic::{AtomicU32, Ordering};

// `Brand` and `Tag` both count *down* from u32::MAX. This drastically reduces
// the chance that an expired alloc's tag will trigger a false positive: it's
// more likely to be a very low number, like 1 or 2, than a very high number.
//
// This is *not* a soundness issue: since `Alloc`s aren't safely clonable, nor
// able to be deallocated in the wrong allocator, the only way the situation
// could arise is if someone unsoundly cloned an `Alloc` and tried to
// double-drop it, which breaks the safety invariants of `Alloc::clone`.

/// A unique identifier for an [`Allocator`](crate::Allocator).
#[derive(PartialEq, Eq)]
pub struct Brand(u32);

impl Brand {
    /// Create a new, unique brand.
    ///
    /// This is not, nor can it be, `const`. If you need to have a `const`
    /// allocator, e.g. in a `static`, consider [`Static`](crate::Static).
    pub fn new() -> Self {
        static INC: AtomicU32 = AtomicU32::new(u32::MAX);

        let brand = INC.fetch_sub(1, Ordering::Relaxed);
        debug_assert!(brand != 0, "allocator brand counter overflowed");
        Brand(brand)
    }

    // /// You probably don't want to do this.
    // ///
    // /// # Safety
    // ///
    // /// *Must not* be used to double-drop an [allocation](crate::Alloc).
    // pub(crate) unsafe fn clone(&self) -> Self {
    //     Self(self.0)
    // }

    /// You probably don't want to do this.
    ///
    /// # Safety
    ///
    /// *Must only* be used to initialize the global platform allocator.
    pub(crate) const unsafe fn platform() -> Self {
        Self(0)
    }
}

impl Default for Brand {
    fn default() -> Self {
        Self::new()
    }
}

/*
pub struct Tag {
    parent: Brand,
    id: u32,
}

impl Tag {
    pub fn new(brand: &Brand) -> Self {
        static INC: AtomicU32 = AtomicU32::new(u32::MAX);

        let id = INC.fetch_sub(1, Ordering::Relaxed);
        debug_assert!(id != 0, "allocation tag counter overflowed");
        Tag { parent: Brand(brand.0), id }
    }

    pub fn parent(&self) -> &Brand {
        &self.parent
    }

    pub fn id(&self) -> u32 {
        self.id
    }

    /// You probably don't want to do this.
    ///
    /// # Safety
    ///
    /// *Must not* be used to double-drop an [allocation](crate::Alloc).
    pub(crate) unsafe fn clone(&self) -> Self {
        Self {
            parent: Brand(self.parent.0),
            id: self.id,
        }
    }
}
*/