use std::task::Poll;
use std::task::Context;
use std::pin::Pin;
use std::ops::{Deref, DerefMut};
use std::future::Future;
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::cell::UnsafeCell;
use std::fmt;
pub unsafe auto trait PSafe {}
impl<T: ?Sized> !PSafe for *const T {}
impl<T: ?Sized> !PSafe for *mut T {}
impl<T> !PSafe for &T {}
impl<T> !PSafe for &mut T {}
impl !PSafe for std::fs::File {}
impl<T: ?Sized> !PSafe for UnsafeCell<T> {}
pub unsafe auto trait TxOutSafe {}
impl<T: ?Sized> !TxOutSafe for *const T {}
impl<T: ?Sized> !TxOutSafe for *mut T {}
impl<T: ?Sized> !TxOutSafe for &mut T {}
impl<T: ?Sized> !TxOutSafe for UnsafeCell<T> {}
unsafe impl TxOutSafe for String {}
unsafe impl<T> TxOutSafe for std::thread::JoinHandle<T> {}
unsafe impl<T> TxOutSafe for Vec<std::thread::JoinHandle<T>> {}
pub unsafe auto trait TxInSafe {}
pub unsafe auto trait LooseTxInUnsafe {}
pub struct AssertTxInSafe<T: LooseTxInUnsafe>(pub T);
impl<T: ?Sized> !TxInSafe for *mut T {}
impl<T: ?Sized> !TxInSafe for &mut T {}
impl<T: ?Sized> !TxInSafe for UnsafeCell<T> {}
impl<T: LooseTxInUnsafe> UnwindSafe for AssertTxInSafe<T> {}
impl<T: LooseTxInUnsafe> RefUnwindSafe for AssertTxInSafe<T> {}
unsafe impl<T: LooseTxInUnsafe> TxInSafe for AssertTxInSafe<T> {}
impl<T: LooseTxInUnsafe> Deref for AssertTxInSafe<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}
impl<T: LooseTxInUnsafe> DerefMut for AssertTxInSafe<T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.0
}
}
impl<R, F: FnOnce() -> R> FnOnce<()> for AssertTxInSafe<F>
where F: LooseTxInUnsafe{
type Output = R;
extern "rust-call" fn call_once(self, _args: ()) -> R {
(self.0)()
}
}
impl<T: fmt::Debug + LooseTxInUnsafe> fmt::Debug for AssertTxInSafe<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("AssertUnwindSafe").field(&self.0).finish()
}
}
impl<F: Future + LooseTxInUnsafe> Future for AssertTxInSafe<F> {
type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let pinned_field = unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) };
F::poll(pinned_field, cx)
}
}
pub unsafe auto trait VSafe {}