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.
5#![no_std]
6use core::ops::{Deref, DerefMut};
78/// Wraps a type to make it implement `Send`.
9#[repr(transparent)]
10pub struct Send<T>(T);
1112impl<T> Send<T> {
13/// # 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> core::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> {
38fn deref_mut(&mut self) -> &mut Self::Target {
39&mut self.0
40}
41}
4243/// Wraps a type to make it implement `Sync`.
44#[repr(transparent)]
45pub struct Sync<T>(T);
4647impl<T> Sync<T> {
48/// # Safety
49 ///
50 /// This is not a magic way to make `t` `Sync`. It is a way to tell the compiler `t` is `Sync`
51 /// and you should only call this method if you are sure this is not a lie.
52pub unsafe fn new(t: T) -> Self {
53 Sync(t)
54 }
5556/// Destroy wrapper and get original type.
57pub fn unwrap(self) -> T {
58self.0
59}
60}
6162unsafe impl<T> core::marker::Sync for Sync<T> {}
6364impl<T> Deref for Sync<T> {
65type Target = T;
6667fn deref(&self) -> &Self::Target {
68&self.0
69}
70}
7172impl<T> DerefMut for Sync<T> {
73fn deref_mut(&mut self) -> &mut Self::Target {
74&mut self.0
75}
76}
7778/// Wraps a type to make it implement `Send` and `Sync`.
79#[repr(transparent)]
80pub struct SendSync<T>(T);
8182impl<T> SendSync<T> {
83/// # Safety
84 ///
85 /// This is not a magic way to make `t` `Send` and `Sync`. It is a way to tell the compiler `t`
86 /// is `Send` and `Sync` and you should only call this method if you are sure this is not a lie.
87pub unsafe fn new(t: T) -> Self {
88 SendSync(t)
89 }
9091/// Destroy wrapper and get original type.
92pub fn unwrap(self) -> T {
93self.0
94}
95}
9697unsafe impl<T> core::marker::Send for SendSync<T> {}
98unsafe impl<T> core::marker::Sync for SendSync<T> {}
99100impl<T> Deref for SendSync<T> {
101type Target = T;
102103fn deref(&self) -> &Self::Target {
104&self.0
105}
106}
107108impl<T> DerefMut for SendSync<T> {
109fn deref_mut(&mut self) -> &mut Self::Target {
110&mut self.0
111}
112}