//! Wrapper type for partially-`unsafe` usage of `T: !Send`. //---------------------------------------------------------------------------------------------------- Import use std::{ borrow::Borrow, ops::{Deref, DerefMut}, }; use bytemuck::TransparentWrapper; //---------------------------------------------------------------------------------------------------- Aliases #[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, TransparentWrapper)] #[repr(transparent)] /// A wrapper type that `unsafe`ly implements `Send` for any `T`. /// /// This is a marker/wrapper type that allows wrapping /// any type `T` such that it implements `Send`. /// /// This is to be used when `T` is `Send`, but only in certain /// situations not provable to the compiler, or is otherwise a /// a pain to prove and/or less efficient. /// /// It is up to the users of this type to ensure their /// usage of `UnsafeSendable` are actually safe. /// /// Notably, `heed`'s table type uses this inside `service`. pub(crate) struct UnsafeSendable(T); #[expect(clippy::non_send_fields_in_send_ty)] // SAFETY: Users ensure that their usage of this type is safe. unsafe impl Send for UnsafeSendable {} impl UnsafeSendable { /// Create a new [`UnsafeSendable`]. /// /// # Safety /// By constructing this type, you must ensure the usage /// of the resulting `Self` is follows all the [`Send`] rules. pub(crate) const unsafe fn new(t: T) -> Self { Self(t) } /// Extract the inner `T`. #[expect(dead_code)] pub(crate) fn into_inner(self) -> T { self.0 } } impl Borrow for UnsafeSendable { fn borrow(&self) -> &T { &self.0 } } impl AsRef for UnsafeSendable { fn as_ref(&self) -> &T { &self.0 } } impl AsMut for UnsafeSendable { fn as_mut(&mut self) -> &mut T { &mut self.0 } } impl Deref for UnsafeSendable { type Target = T; fn deref(&self) -> &Self::Target { &self.0 } } impl DerefMut for UnsafeSendable { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } //---------------------------------------------------------------------------------------------------- Tests #[cfg(test)] mod test { // use super::*; }