use std::hash::{Hash, Hasher};
use std::ops::{Deref, DerefMut};
pub unsafe trait GcSafe {}
pub struct GcSafeWrapper<T> {
pub v: T,
}
unsafe impl<T> GcSafe for GcSafeWrapper<T> {}
impl<T> GcSafeWrapper<T> {
pub fn new(v: T) -> Self
where
T: Send + 'static,
{
Self { v }
}
pub unsafe fn new_unsafe(v: T) -> Self {
Self { v }
}
pub fn take(self) -> T {
self.v
}
}
impl<T: Send + Clone> Clone for GcSafeWrapper<T> {
fn clone(&self) -> Self {
Self { v: self.v.clone() }
}
}
impl<T: Send + Copy> Copy for GcSafeWrapper<T> {}
impl<T: Send + Default> Default for GcSafeWrapper<T> {
fn default() -> Self {
Self { v: T::default() }
}
}
impl<T: Send> Deref for GcSafeWrapper<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.v
}
}
impl<T: Send> DerefMut for GcSafeWrapper<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.v
}
}
impl<T: Send + Hash> Hash for GcSafeWrapper<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.v.hash(state);
}
}
#[allow(clippy::partialeq_ne_impl)]
impl<T: Send + PartialEq> PartialEq for GcSafeWrapper<T> {
fn eq(&self, other: &Self) -> bool {
self.v.eq(other)
}
fn ne(&self, other: &Self) -> bool {
self.v.ne(other)
}
}
impl<T: Send + Eq> Eq for GcSafeWrapper<T> {}