use alloc::boxed::Box;
pub trait Any {}
impl<T: ?Sized> Any for T {}
pub unsafe trait ToBoxedDyn<T: ?Sized> {
fn to_boxed_unsize(value: Self) -> Box<T>;
}
#[cfg(not(feature = "unstable"))]
unsafe impl<'a, T: 'a> ToBoxedDyn<dyn Any + 'a> for T {
fn to_boxed_unsize(value: Self) -> Box<dyn Any + 'a> {
Box::new(value)
}
}
#[cfg(not(feature = "unstable"))]
unsafe impl<'a, T: Send + 'a> ToBoxedDyn<dyn Send + 'a> for T {
fn to_boxed_unsize(value: Self) -> Box<dyn Send + 'a> {
Box::new(value)
}
}
#[cfg(not(feature = "unstable"))]
unsafe impl<'a, T: Sync + 'a> ToBoxedDyn<dyn Sync + 'a> for T {
fn to_boxed_unsize(value: Self) -> Box<dyn Sync + 'a> {
Box::new(value)
}
}
#[cfg(not(feature = "unstable"))]
unsafe impl<'a, T: Send + Sync + 'a> ToBoxedDyn<dyn Send + Sync + 'a> for T {
fn to_boxed_unsize(value: Self) -> Box<dyn Send + Sync + 'a> {
Box::new(value)
}
}
#[cfg(feature = "unstable")]
unsafe impl<T: ?Sized, U: core::marker::Unsize<T>> ToBoxedDyn<T> for U
where
T: core::ptr::Pointee<Metadata = core::ptr::DynMetadata<T>>,
{
fn to_boxed_unsize(value: Self) -> Box<T> {
Box::<U>::new(value)
}
}
pub unsafe trait FnPtr: Sized + Copy + Send + Sync {
type CC: Default + Copy + Send + Sync;
#[cfg(all(not(doc), feature = "tuple_trait"))]
type Args<'a, 'b, 'c>: core::marker::Tuple;
#[cfg(any(doc, not(feature = "tuple_trait")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
type Args<'a, 'b, 'c>;
type Ret<'a, 'b, 'c>;
unsafe fn call<'a, 'b, 'c>(self, args: Self::Args<'a, 'b, 'c>) -> Self::Ret<'a, 'b, 'c>;
unsafe fn from_ptr(ptr: *const ()) -> Self;
fn to_ptr(self) -> *const ();
fn make_once_thunk<F>(fun: F) -> impl FnOnceThunk<Self>
where
F: for<'a, 'b, 'c> PackedFnOnce<'a, 'b, 'c, Self>;
fn make_mut_thunk<F>(fun: F) -> impl FnMutThunk<Self>
where
F: for<'a, 'b, 'c> PackedFnMut<'a, 'b, 'c, Self>;
fn make_thunk<F>(fun: F) -> impl FnThunk<Self>
where
F: for<'a, 'b, 'c> PackedFn<'a, 'b, 'c, Self>;
}
pub unsafe trait FnOnceThunk<B: FnPtr>: Sized {
const THUNK_TEMPLATE_ONCE: *const u8;
unsafe fn call_once<'a, 'b, 'c>(self, args: B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c>;
}
pub unsafe trait FnMutThunk<B: FnPtr>: FnOnceThunk<B> {
const THUNK_TEMPLATE_MUT: *const u8;
unsafe fn call_mut<'a, 'b, 'c>(&mut self, args: B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c>;
}
pub unsafe trait FnThunk<B: FnPtr>: FnMutThunk<B> {
const THUNK_TEMPLATE: *const u8;
unsafe fn call<'a, 'b, 'c>(&self, args: B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c>;
}
pub trait PackedFnOnce<'a, 'b, 'c, B: FnPtr>:
FnOnce(B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c>
{
}
impl<'a, 'b, 'c, B: FnPtr, F> PackedFnOnce<'a, 'b, 'c, B> for F where
F: FnOnce(B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c>
{
}
pub trait PackedFnMut<'a, 'b, 'c, B: FnPtr>:
FnMut(B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c>
{
}
impl<'a, 'b, 'c, B: FnPtr, F> PackedFnMut<'a, 'b, 'c, B> for F where
F: FnMut(B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c>
{
}
pub trait PackedFn<'a, 'b, 'c, B: FnPtr>: Fn(B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c> {}
impl<'a, 'b, 'c, B: FnPtr, F> PackedFn<'a, 'b, 'c, B> for F where
F: Fn(B::Args<'a, 'b, 'c>) -> B::Ret<'a, 'b, 'c>
{
}