use core::mem;
pub struct Variant;
pub struct Invariant;
pub struct Static;
pub struct Unchecked;
pub struct Enforced;
pub struct Unenforced;
pub struct AlwaysValid;
pub struct MaybeInvalid;
pub mod neglect;
#[rustfmt::skip]
pub mod from_type;
#[rustfmt::skip]
pub mod from_layout;
pub struct Stable;
pub struct Unstable;
pub unsafe trait TransmuteInto<U, O = ()>: UnsafeTransmuteInto<U>
where
O: neglect::TransmuteOptions,
{
fn transmute_into(self) -> U
where
Self: Sized;
}
unsafe impl<T, U, O> TransmuteInto<U, O> for T
where
U: TransmuteFrom<T, O>,
O: neglect::TransmuteOptions,
Self: UnsafeTransmuteInto<U>,
{
#[inline(always)]
fn transmute_into(self) -> U {
U::transmute_from(self)
}
}
pub trait StableTransmuteInto<U>: TransmuteInto<U> {
fn transmute_into(self) -> U;
}
impl<T, U> StableTransmuteInto<U> for T
where
T: TransmuteInto<U>,
{
#[inline(always)]
fn transmute_into(self) -> U
{
self.transmute_into()
}
}
pub unsafe trait TransmuteFrom<T, O = ()>: Sized
where
O: neglect::TransmuteOptions,
{
fn transmute_from(from: T) -> Self;
}
unsafe impl<T, U, O> TransmuteFrom<T, O> for U
where
U: UnsafeTransmuteFrom<T, O>,
O: neglect::TransmuteOptions,
{
#[inline(always)]
fn transmute_from(from: T) -> U {
unsafe { U::unsafe_transmute_from(from) }
}
}
#[inline(always)]
pub fn safe_transmute<T, U, O>(from: T) -> U
where
U: from_type::FromType<T,
Variant,
<O as neglect::UnsafeTransmuteOptions>::Alignment,
<O as neglect::UnsafeTransmuteOptions>::Transparency,
<O as neglect::UnsafeTransmuteOptions>::Stability,
<O as neglect::UnsafeTransmuteOptions>::Validity,
>,
O: neglect::TransmuteOptions,
{
unsafe {
let to = mem::transmute_copy(&from);
mem::forget(from);
to
}
}
pub unsafe trait UnsafeTransmuteInto<U, O = ()>: Sized
where
O: neglect::UnsafeTransmuteOptions,
{
unsafe fn unsafe_transmute_into(self) -> U;
}
unsafe impl<T, U, O> UnsafeTransmuteInto<U, O> for T
where
U: UnsafeTransmuteFrom<T, O>,
O: neglect::UnsafeTransmuteOptions,
{
#[inline(always)]
unsafe fn unsafe_transmute_into(self) -> U {
unsafe { U::unsafe_transmute_from(self) }
}
}
pub unsafe trait UnsafeTransmuteFrom<T, O = ()>: Sized
where
O: neglect::UnsafeTransmuteOptions,
{
unsafe fn unsafe_transmute_from(from: T) -> Self;
}
unsafe impl<T, U, O> UnsafeTransmuteFrom<T, O> for U
where
U: from_type::FromType<T,
Variant,
<O as neglect::UnsafeTransmuteOptions>::Alignment,
<O as neglect::UnsafeTransmuteOptions>::Transparency,
<O as neglect::UnsafeTransmuteOptions>::Stability,
<O as neglect::UnsafeTransmuteOptions>::Validity,
>,
O: neglect::UnsafeTransmuteOptions,
{
#[inline(always)]
unsafe fn unsafe_transmute_from(from: T) -> U {
unsafe { unsafe_transmute::<T, U, O>(from) }
}
}
#[inline(always)]
pub unsafe fn unsafe_transmute<T, U, O>(from: T) -> U
where
U: from_type::FromType<T,
Variant,
<O as neglect::UnsafeTransmuteOptions>::Alignment,
<O as neglect::UnsafeTransmuteOptions>::Transparency,
<O as neglect::UnsafeTransmuteOptions>::Stability,
<O as neglect::UnsafeTransmuteOptions>::Validity>,
O: neglect::UnsafeTransmuteOptions,
{
let to = mem::transmute_copy(&from);
mem::forget(from);
to
}