1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
//! Please do not use this crate. The Rust compiler tries to protect you for a reason. Do under no
//! circumstances use this to silence some compiler error you do not understand. Only use this if
//! you do understand why your type is `Send` and or `Sync`, and also understand why the compiler
//! disagrees with you.
use std::ops::{Deref, DerefMut};
/// Wraps a type to make it implement `Send`.
#[repr(transparent)]
pub struct Send<T>(T);
impl<T> Send<T> {
/// # Safety
///
/// This is not a magic way to make `t` `Send`. It is a way to tell the compiler `t` is `Send`
/// and you should only call this method if you are sure this is not a lie.
pub unsafe fn new(t: T) -> Self {
Send(t)
}
/// Destroy wrapper and get original type.
pub fn unwrap(self) -> T {
self.0
}
}
unsafe impl<T> std::marker::Send for Send<T> {}
impl<T> Deref for Send<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> DerefMut for Send<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
/// Wraps a type to make it implement `Sync`.
#[repr(transparent)]
pub struct Sync<T>(T);
impl<T> Sync<T> {
/// # Safety
///
/// This is not a magic way to make `t` `Sync`. It is a way to tell the compiler `t` is `Sync`
/// and you should only call this method if you are sure this is not a lie.
pub unsafe fn new(t: T) -> Self {
Sync(t)
}
/// Destroy wrapper and get original type.
pub fn unwrap(self) -> T {
self.0
}
}
unsafe impl<T> std::marker::Sync for Sync<T> {}
impl<T> Deref for Sync<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> DerefMut for Sync<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
/// Wraps a type to make it implement `Send` and `Sync`.
#[repr(transparent)]
pub struct SendSync<T>(T);
impl<T> SendSync<T> {
/// # Safety
///
/// This is not a magic way to make `t` `Send` and `Sync`. It is a way to tell the compiler `t`
/// is `Send` and `Sync` and you should only call this method if you are sure this is not a lie.
pub unsafe fn new(t: T) -> Self {
SendSync(t)
}
/// Destroy wrapper and get original type.
pub fn unwrap(self) -> T {
self.0
}
}
unsafe impl<T> std::marker::Send for SendSync<T> {}
unsafe impl<T> std::marker::Sync for SendSync<T> {}
impl<T> Deref for SendSync<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> DerefMut for SendSync<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}