nlib 0.1.3

Nate's library. Various things or macro patterns I use to aid in more succint Rust programming.
Documentation
// Copyright 2025 Nathan Sizemore <nathanrsizemore@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.

use std::cell::UnsafeCell;

/// `UnsafeCell` that is `Sync` if `T: Sync`.
/// - Provides **no** synchronization; you must avoid data races.
/// - Useful for building primitives or when `T` handles its own sync (atomics).
#[repr(transparent)]
pub struct SyncUnsafeCell<T> {
    inner: UnsafeCell<T>,
}

impl<T> SyncUnsafeCell<T> {
    pub const fn new(item: T) -> Self {
        Self {
            inner: UnsafeCell::new(item),
        }
    }

    /// Raw mutable pointer to inner `T`.
    /// # Safety
    /// Using this requires external synchronization.
    pub const fn get(&self) -> *mut T {
        self.inner.get()
    }

    /// Unique mutable reference (safe due to `&mut self` exclusivity).
    pub const fn get_mut(&mut self) -> &mut T {
        self.inner.get_mut()
    }
}

unsafe impl<T: Sync> Sync for SyncUnsafeCell<T> {}