mod test;
use crate::{Immutable, FromOcts};
use core::cell::{Cell, UnsafeCell};
use core::cmp::Reverse;
use core::convert::Infallible;
use core::marker::{PhantomData, PhantomPinned};
use core::mem::ManuallyDrop;
use core::ptr::NonNull;
use core::num::{NonZero, Saturating, Wrapping};
use core::slice;
#[cfg(target_arch = "x86")]
use core::arch::x86::{
__m128,
__m128bh,
__m128d,
__m128i,
__m256,
__m256bh,
__m256d,
__m256i,
__m512,
__m512bh,
__m512d,
__m512i,
};
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::{
__m128,
__m128bh,
__m128d,
__m128i,
__m256,
__m256bh,
__m256d,
__m256i,
__m512,
__m512bh,
__m512d,
__m512i,
};
#[cfg(target_has_atomic = "8")]
use core::sync::atomic::{AtomicBool, AtomicI8, AtomicU8};
#[cfg(target_has_atomic = "16")]
use core::sync::atomic::{AtomicI16, AtomicU16};
#[cfg(target_has_atomic = "32")]
use core::sync::atomic::{AtomicI32, AtomicU32};
#[cfg(target_has_atomic = "64")]
use core::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(target_has_atomic = "128")]
use core::sync::atomic::{AtomicI128, AtomicU128};
#[cfg(target_has_atomic = "ptr")]
use core::sync::atomic::AtomicPtr;
pub unsafe trait IntoOcts {
#[inline(always)]
#[must_use]
fn as_octs(&self) -> &[u8]
where
Self: Immutable,
{
let len = size_of_val(self);
let ptr = &raw const *self as *const u8;
unsafe { slice::from_raw_parts(ptr, len) }
}
#[inline(always)]
#[must_use]
fn as_octs_mut(&mut self) -> &mut [u8]
where
Self: FromOcts,
{
let len = size_of_val(self);
let ptr = &raw mut *self as *mut u8;
unsafe { slice::from_raw_parts_mut(ptr, len) }
}
}
unsafe impl<T: IntoOcts, const N: usize> IntoOcts for [T; N] {}
#[cfg(target_has_atomic = "8")]
unsafe impl IntoOcts for AtomicBool {}
#[cfg(target_has_atomic = "128")]
unsafe impl IntoOcts for AtomicI128 {}
#[cfg(target_has_atomic = "16")]
unsafe impl IntoOcts for AtomicI16 {}
#[cfg(target_has_atomic = "32")]
unsafe impl IntoOcts for AtomicI32 {}
#[cfg(target_has_atomic = "64")]
unsafe impl IntoOcts for AtomicI64 {}
#[cfg(target_has_atomic = "8")]
unsafe impl IntoOcts for AtomicI8 {}
#[cfg(target_has_atomic = "ptr")]
unsafe impl<T> IntoOcts for AtomicPtr<T> {}
#[cfg(target_has_atomic = "128")]
unsafe impl IntoOcts for AtomicU128 {}
#[cfg(target_has_atomic = "16")]
unsafe impl IntoOcts for AtomicU16 {}
#[cfg(target_has_atomic = "32")]
unsafe impl IntoOcts for AtomicU32 {}
#[cfg(target_has_atomic = "64")]
unsafe impl IntoOcts for AtomicU64 {}
#[cfg(target_has_atomic = "8")]
unsafe impl IntoOcts for AtomicU8 {}
unsafe impl IntoOcts for bool {}
unsafe impl<T: IntoOcts> IntoOcts for Cell<T> {}
unsafe impl IntoOcts for char {}
#[cfg(feature = "f128")]
unsafe impl IntoOcts for f128 {}
#[cfg(feature = "f16")]
unsafe impl IntoOcts for f16 {}
unsafe impl IntoOcts for f32 {}
unsafe impl IntoOcts for f64 {}
unsafe impl IntoOcts for i128 {}
unsafe impl IntoOcts for i16 {}
unsafe impl IntoOcts for i32 {}
unsafe impl IntoOcts for i64 {}
unsafe impl IntoOcts for i8 {}
unsafe impl IntoOcts for Infallible {}
unsafe impl IntoOcts for isize {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m128 {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m128 {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m128bh {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m128bh {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m128d {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m128d {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m128i {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m128i {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m256 {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m256 {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m256bh {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m256bh {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m256d {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m256d {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m256i {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m256i {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m512 {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m512 {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m512bh {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m512bh {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m512d {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m512d {}
#[cfg(target_arch = "x86")]
unsafe impl IntoOcts for __m512i {}
#[cfg(target_arch = "x86_64")]
unsafe impl IntoOcts for __m512i {}
unsafe impl<T: IntoOcts> IntoOcts for ManuallyDrop<T> {}
unsafe impl IntoOcts for NonZero<i128> {}
unsafe impl IntoOcts for NonZero<i16> {}
unsafe impl IntoOcts for NonZero<i32> {}
unsafe impl IntoOcts for NonZero<i64> {}
unsafe impl IntoOcts for NonZero<i8> {}
unsafe impl IntoOcts for NonZero<isize> {}
unsafe impl IntoOcts for NonZero<u128> {}
unsafe impl IntoOcts for NonZero<u16> {}
unsafe impl IntoOcts for NonZero<u32> {}
unsafe impl IntoOcts for NonZero<u64> {}
unsafe impl IntoOcts for NonZero<u8> {}
unsafe impl IntoOcts for NonZero<usize> {}
unsafe impl<T> IntoOcts for Option<NonNull<T>> {}
unsafe impl IntoOcts for Option<NonZero<i128>> {}
unsafe impl IntoOcts for Option<NonZero<i16>> {}
unsafe impl IntoOcts for Option<NonZero<i32>> {}
unsafe impl IntoOcts for Option<NonZero<i64>> {}
unsafe impl IntoOcts for Option<NonZero<i8>> {}
unsafe impl IntoOcts for Option<NonZero<isize>> {}
unsafe impl IntoOcts for Option<NonZero<u128>> {}
unsafe impl IntoOcts for Option<NonZero<u16>> {}
unsafe impl IntoOcts for Option<NonZero<u32>> {}
unsafe impl IntoOcts for Option<NonZero<u64>> {}
unsafe impl IntoOcts for Option<NonZero<u8>> {}
unsafe impl IntoOcts for Option<NonZero<usize>> {}
unsafe impl<T: ?Sized> IntoOcts for PhantomData<T> {}
unsafe impl IntoOcts for PhantomPinned {}
unsafe impl<T> IntoOcts for *const T {}
unsafe impl<T> IntoOcts for *mut T {}
unsafe impl<T: IntoOcts> IntoOcts for Reverse<T> {}
unsafe impl<T: IntoOcts> IntoOcts for Saturating<T> {}
unsafe impl<T: IntoOcts> IntoOcts for [T] {}
unsafe impl IntoOcts for str {}
#[cfg_attr(feature = "unstable_docs", doc(fake_variadic))]
unsafe impl<T: IntoOcts> IntoOcts for (T,) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T, T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T, T, T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T, T, T, T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T, T, T, T, T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T, T, T, T, T, T, T, T) {}
#[doc(hidden)]
unsafe impl<T: IntoOcts> IntoOcts for (T, T, T, T, T, T, T, T, T, T, T, T) {}
unsafe impl IntoOcts for u128 {}
unsafe impl IntoOcts for u16 {}
unsafe impl IntoOcts for u32 {}
unsafe impl IntoOcts for u64 {}
unsafe impl IntoOcts for u8 {}
unsafe impl IntoOcts for () {}
unsafe impl<T: IntoOcts> IntoOcts for UnsafeCell<T> {}
unsafe impl IntoOcts for usize {}
unsafe impl<T: IntoOcts> IntoOcts for Wrapping<T> {}