1//! Please do not use this crate. The Rust compiler tries to protect you for a reason. Do under no
2//! circumstances use this to silence some compiler error you do not understand. Only use this if
3//! you do understand why your type is `Send` and or `Sync`, and also understand why the compiler
4//! disagrees with you.
5use std::ops::{Deref, DerefMut};
67/// Wraps a type to make it implement `Send`.
8#[repr(transparent)]
9pub struct Send<T>(T);
1011impl<T> Send<T> {
1213/// # Safety
14 ///
15 /// This is not a magic way to make `t` `Send`. It is a way to tell the compiler `t` is `Send`
16 /// and you should only call this method if you are sure this is not a lie.
17pub unsafe fn new(t: T) -> Self {
18 Send(t)
19 }
2021/// Destroy wrapper and get original type.
22pub fn unwrap(self) -> T {
23self.0
24}
25}
2627unsafe impl<T> std::marker::Send for Send<T> {}
2829impl<T> Deref for Send<T> {
30type Target = T;
3132fn deref(&self) -> &Self::Target {
33&self.0
34}
35}
3637impl<T> DerefMut for Send<T> {
3839fn deref_mut(&mut self) -> &mut Self::Target {
40&mut self.0
41}
42}
4344/// Wraps a type to make it implement `Sync`.
45#[repr(transparent)]
46pub struct Sync<T>(T);
4748impl<T> Sync<T> {
4950/// # Safety
51 ///
52 /// This is not a magic way to make `t` `Sync`. It is a way to tell the compiler `t` is `Sync`
53 /// and you should only call this method if you are sure this is not a lie.
54pub unsafe fn new(t: T) -> Self {
55 Sync(t)
56 }
5758/// Destroy wrapper and get original type.
59pub fn unwrap(self) -> T {
60self.0
61}
62}
6364unsafe impl<T> std::marker::Sync for Sync<T> {}
6566impl<T> Deref for Sync<T> {
67type Target = T;
6869fn deref(&self) -> &Self::Target {
70&self.0
71}
72}
7374impl<T> DerefMut for Sync<T> {
7576fn deref_mut(&mut self) -> &mut Self::Target {
77&mut self.0
78}
79}
8081/// Wraps a type to make it implement `Send` and `Sync`.
82#[repr(transparent)]
83pub struct SendSync<T>(T);
8485impl<T> SendSync<T> {
8687/// # Safety
88 ///
89 /// This is not a magic way to make `t` `Send` and `Sync`. It is a way to tell the compiler `t`
90 /// is `Send` and `Sync` and you should only call this method if you are sure this is not a lie.
91pub unsafe fn new(t: T) -> Self {
92 SendSync(t)
93 }
9495/// Destroy wrapper and get original type.
96pub fn unwrap(self) -> T {
97self.0
98}
99}
100101unsafe impl<T> std::marker::Send for SendSync<T> {}
102unsafe impl<T> std::marker::Sync for SendSync<T> {}
103104impl<T> Deref for SendSync<T> {
105type Target = T;
106107fn deref(&self) -> &Self::Target {
108&self.0
109}
110}
111112impl<T> DerefMut for SendSync<T> {
113114fn deref_mut(&mut self) -> &mut Self::Target {
115&mut self.0
116}
117}