pkecs 9.0.0

Another ECS implementation.
Documentation
//! Custom cell types.

use std::cell::UnsafeCell;

/// A wrapper over [`UnsafeCell`] which provides safe types.
///
/// Usage of this is still unsafe, the caller must verify that aliasing rules aren't violated.
pub struct UncheckedCell<T> {
    cell: UnsafeCell<T>,
}

impl<T> UncheckedCell<T> {
    /// Initializes [`self`] with an inner value.
    pub const fn new(value: T) -> Self {
        let cell = UnsafeCell::new(value);

        Self { cell }
    }

    /// Returns an immutable reference to the value within [`self`].
    pub fn get<'a>(&self) -> &'a T {
        let ptr = self.cell.get();

        unsafe { &*ptr }
    }

    /// Returns a mutable reference to the value within [`self`].
    pub fn get_mut<'a>(&self) -> &'a mut T {
        let ptr = self.cell.get();

        unsafe { &mut *ptr }
    }
}

impl<T> Default for UncheckedCell<T>
    where
        T: Default,
{
    fn default() -> Self {
        let inner = T::default();

        Self::new(inner)
    }
}