Trait PessimizeCast

Source
pub unsafe trait PessimizeCast {
    type Pessimized: Pessimize;

    // Required methods
    fn into_pessimize(self) -> Self::Pessimized;
    unsafe fn from_pessimize(x: Self::Pessimized) -> Self;
}
Expand description

Convert Self back and forth to a Pessimize impl (Pessimize impl helper)

While only a small number of Pessimize types are supported by inline assembly, many standard types can be losslessly converted to a lower-level type (or tuple of types) that implement Pessimize and back in such a way that the runtime costs should be optimized out.

This trait exposes that capability under a common abstraction vocabulary. Combined with the related BorrowPessimize trait, it enables implementation of Pessimize with increased safety reduced boilerplate.

§Safety

By implementing this trait, you guarantee that someone using it as documented will not trigger Undefined Behavior, since the safe Pessimize trait can be automatically implemented on top of it

Required Associated Types§

Source

type Pessimized: Pessimize

Pessimize type that can be converted to and from a Self value

Required Methods§

Source

fn into_pessimize(self) -> Self::Pessimized

Convert Self to Pessimized

Source

unsafe fn from_pessimize(x: Self::Pessimized) -> Self

Convert back from Pessimized to Self

§Safety

A correct implementation of this operation only needs to be safe for the intended purpose of converting Self to Pessimized using into_pessimize(), invoking Pessimize trait operations on the resulting value, and optionally converting the Pessimized value back to Self afterwards via from_pessimize().

The final from_pessimize() operation of this round trip must be performed in the same scope where the initial into_pessimize() operation was called, or a child scope thereof.

Even if Pessimized is Clone, it is strongly advised to treat the Pessimized value from into_pessimize() as a !Clone value: don’t clone or copy it, and stop using it after converting it back to Self. Otherwise, suprising (but safe) behavior may occur.

No other usage of from_pessimize() is safe. To give a few examples of incorrect usage of from_pessimize()

  • Self may contain references to the surrounding stack frame, so even if Pessimized is 'static, letting a Pessimized escape the scope in which into_pessimize() was called before converting it back to Self is unsafe.
  • Self may contain !Clone data like &mut references, so even if Pessimized is Clone, converting two clones of a single Pessimized value back into Self is unsafe. In fact, even using the Pessimize implementation after converting one of the clones to Self is not guaranteed to produce the desired optimization barrier.
  • Self may be !Send, so even if Pessimized is Send, sending a Pessimized value to another thread before calling from_pessimize() on that separate thread is unsafe.
  • Even if two types share the same Pessimized representation, abusing the PessimizeCast trait to perform a cast operation, like casting a reference to another reference with different mutability or lifetime, is unsafe.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl PessimizeCast for bool

Source§

type Pessimized = u8

Source§

fn into_pessimize(self) -> u8

Source§

unsafe fn from_pessimize(inner: u8) -> Self

Source§

impl PessimizeCast for char

Source§

type Pessimized = u32

Source§

fn into_pessimize(self) -> u32

Source§

unsafe fn from_pessimize(inner: u32) -> Self

Source§

impl PessimizeCast for String

Available on crate feature alloc only.
Source§

type Pessimized = Vec<u8>

Source§

fn into_pessimize(self) -> Vec<u8>

Source§

unsafe fn from_pessimize(inner: Vec<u8>) -> Self

Source§

impl PessimizeCast for Layout

Source§

impl PessimizeCast for float64x1x2_t

Available with target feature neon only.
Source§

impl PessimizeCast for float64x1x3_t

Available with target feature neon only.
Source§

impl PessimizeCast for float64x1x4_t

Available with target feature neon only.
Source§

impl PessimizeCast for float64x2x2_t

Available with target feature neon only.
Source§

impl PessimizeCast for float64x2x3_t

Available with target feature neon only.
Source§

impl PessimizeCast for float64x2x4_t

Available with target feature neon only.
Source§

impl PessimizeCast for Simd<f64, 1>

Available on crate feature nightly and target feature neon only.
Source§

impl PessimizeCast for Simd<f64, 2>

Available on crate feature nightly and target feature neon only.
Source§

impl PessimizeCast for Error

Source§

type Pessimized = ()

Source§

fn into_pessimize(self)

Source§

unsafe fn from_pessimize(inner: ()) -> Self

Source§

impl PessimizeCast for PhantomPinned

Source§

type Pessimized = ()

Source§

fn into_pessimize(self)

Source§

unsafe fn from_pessimize(inner: ()) -> Self

Source§

impl PessimizeCast for Ipv4Addr

Available on crate feature std only.
Source§

type Pessimized = u32

Source§

fn into_pessimize(self) -> u32

Source§

unsafe fn from_pessimize(inner: u32) -> Self

Source§

impl PessimizeCast for SocketAddrV4

Available on crate feature std only.
Source§

impl PessimizeCast for RangeFull

Source§

type Pessimized = ()

Source§

fn into_pessimize(self)

Source§

unsafe fn from_pessimize(inner: ()) -> Self

Source§

impl PessimizeCast for AtomicBool

Available on target_has_atomic="8" only.
Source§

impl PessimizeCast for AtomicI8

Available on target_has_atomic="8" only.
Source§

type Pessimized = i8

Source§

fn into_pessimize(self) -> i8

Source§

unsafe fn from_pessimize(inner: i8) -> Self

Source§

impl PessimizeCast for AtomicI16

Available on target_has_atomic="16" only.
Source§

type Pessimized = i16

Source§

fn into_pessimize(self) -> i16

Source§

unsafe fn from_pessimize(inner: i16) -> Self

Source§

impl PessimizeCast for AtomicI32

Available on target_has_atomic="32" only.
Source§

type Pessimized = i32

Source§

fn into_pessimize(self) -> i32

Source§

unsafe fn from_pessimize(inner: i32) -> Self

Source§

impl PessimizeCast for AtomicI64

Available on target_has_atomic="64" and 64-bit only.
Source§

type Pessimized = i64

Source§

fn into_pessimize(self) -> i64

Source§

unsafe fn from_pessimize(inner: i64) -> Self

Source§

impl PessimizeCast for AtomicIsize

Available on target_has_atomic="ptr" only.
Source§

impl PessimizeCast for AtomicU8

Available on target_has_atomic="8" only.
Source§

type Pessimized = u8

Source§

fn into_pessimize(self) -> u8

Source§

unsafe fn from_pessimize(inner: u8) -> Self

Source§

impl PessimizeCast for AtomicU16

Available on target_has_atomic="16" only.
Source§

type Pessimized = u16

Source§

fn into_pessimize(self) -> u16

Source§

unsafe fn from_pessimize(inner: u16) -> Self

Source§

impl PessimizeCast for AtomicU32

Available on target_has_atomic="32" only.
Source§

type Pessimized = u32

Source§

fn into_pessimize(self) -> u32

Source§

unsafe fn from_pessimize(inner: u32) -> Self

Source§

impl PessimizeCast for AtomicU64

Available on target_has_atomic="64" and 64-bit only.
Source§

type Pessimized = u64

Source§

fn into_pessimize(self) -> u64

Source§

unsafe fn from_pessimize(inner: u64) -> Self

Source§

impl PessimizeCast for AtomicUsize

Available on target_has_atomic="ptr" only.
Source§

impl PessimizeCast for OsString

Available on crate feature std and (Unix or WASI) only.
Source§

type Pessimized = Vec<u8>

Source§

fn into_pessimize(self) -> Vec<u8>

Source§

unsafe fn from_pessimize(inner: Vec<u8>) -> Self

Source§

impl PessimizeCast for File

Available on crate feature std and (Unix or Windows) only.
Source§

impl PessimizeCast for Permissions

Available on crate feature std and Unix only.
Source§

type Pessimized = u32

Source§

fn into_pessimize(self) -> u32

Source§

unsafe fn from_pessimize(inner: u32) -> Self

Source§

impl PessimizeCast for Empty

Available on crate feature std only.
Source§

type Pessimized = ()

Source§

fn into_pessimize(self)

Source§

unsafe fn from_pessimize(inner: ()) -> Self

Source§

impl PessimizeCast for Repeat

Available on crate feature std only.
Source§

type Pessimized = u8

Source§

fn into_pessimize(self) -> u8

Source§

unsafe fn from_pessimize(inner: u8) -> Self

Source§

impl PessimizeCast for Sink

Available on crate feature std only.
Source§

type Pessimized = ()

Source§

fn into_pessimize(self)

Source§

unsafe fn from_pessimize(inner: ()) -> Self

Source§

impl PessimizeCast for TcpListener

Available on crate feature std and (Unix or Windows) only.
Source§

impl PessimizeCast for TcpStream

Available on crate feature std and (Unix or Windows) only.
Source§

impl PessimizeCast for UdpSocket

Available on crate feature std and (Unix or Windows) only.
Source§

impl PessimizeCast for PathBuf

Available on crate feature std and (Unix or WASI) only.
Source§

impl PessimizeCast for ExitStatus

Available on (crate feature std or test) and Unix only.
Source§

type Pessimized = i32

Source§

fn into_pessimize(self) -> i32

Source§

unsafe fn from_pessimize(inner: i32) -> Self

Source§

impl PessimizeCast for Output

Available on (crate feature std or test) and Unix only.
Source§

impl PessimizeCast for NonZeroI8

Source§

type Pessimized = i8

Source§

fn into_pessimize(self) -> i8

Source§

unsafe fn from_pessimize(inner: i8) -> Self

Source§

impl PessimizeCast for NonZeroI16

Source§

type Pessimized = i16

Source§

fn into_pessimize(self) -> i16

Source§

unsafe fn from_pessimize(inner: i16) -> Self

Source§

impl PessimizeCast for NonZeroI32

Source§

type Pessimized = i32

Source§

fn into_pessimize(self) -> i32

Source§

unsafe fn from_pessimize(inner: i32) -> Self

Source§

impl PessimizeCast for NonZeroI64

Source§

type Pessimized = i64

Source§

fn into_pessimize(self) -> i64

Source§

unsafe fn from_pessimize(inner: i64) -> Self

Source§

impl PessimizeCast for NonZeroIsize

Source§

impl PessimizeCast for NonZeroU8

Source§

type Pessimized = u8

Source§

fn into_pessimize(self) -> u8

Source§

unsafe fn from_pessimize(inner: u8) -> Self

Source§

impl PessimizeCast for NonZeroU16

Source§

type Pessimized = u16

Source§

fn into_pessimize(self) -> u16

Source§

unsafe fn from_pessimize(inner: u16) -> Self

Source§

impl PessimizeCast for NonZeroU32

Source§

type Pessimized = u32

Source§

fn into_pessimize(self) -> u32

Source§

unsafe fn from_pessimize(inner: u32) -> Self

Source§

impl PessimizeCast for NonZeroU64

Source§

type Pessimized = u64

Source§

fn into_pessimize(self) -> u64

Source§

unsafe fn from_pessimize(inner: u64) -> Self

Source§

impl PessimizeCast for NonZeroUsize

Source§

impl<'a, T: ?Sized> PessimizeCast for &'a T
where NonNull<T>: Pessimize,

Source§

impl<'a, T: ?Sized> PessimizeCast for &'a mut T
where NonNull<T>: Pessimize,

Source§

impl<Idx: Clone + Pessimize> PessimizeCast for Range<Idx>

Source§

impl<Idx: Clone + Pessimize> PessimizeCast for RangeFrom<Idx>

Source§

type Pessimized = Idx

Source§

fn into_pessimize(self) -> Idx

Source§

unsafe fn from_pessimize(inner: Idx) -> Self

Source§

impl<Idx: Clone + Pessimize> PessimizeCast for RangeInclusive<Idx>

Source§

impl<Idx: Clone + Pessimize> PessimizeCast for RangeTo<Idx>

Source§

type Pessimized = Idx

Source§

fn into_pessimize(self) -> Idx

Source§

unsafe fn from_pessimize(inner: Idx) -> Self

Source§

impl<Idx: Clone + Pessimize> PessimizeCast for RangeToInclusive<Idx>

Source§

type Pessimized = Idx

Source§

fn into_pessimize(self) -> Idx

Source§

unsafe fn from_pessimize(inner: Idx) -> Self

Source§

impl<R> PessimizeCast for fn() -> R

Source§

impl<R, A1, A2, A3, A4, A5, A6, A7, A8> PessimizeCast for fn(A1, A2, A3, A4, A5, A6, A7, A8) -> R

Source§

impl<R, A2, A3, A4, A5, A6, A7, A8> PessimizeCast for fn(A2, A3, A4, A5, A6, A7, A8) -> R

Source§

impl<R, A3, A4, A5, A6, A7, A8> PessimizeCast for fn(A3, A4, A5, A6, A7, A8) -> R

Source§

impl<R, A4, A5, A6, A7, A8> PessimizeCast for fn(A4, A5, A6, A7, A8) -> R

Source§

impl<R, A5, A6, A7, A8> PessimizeCast for fn(A5, A6, A7, A8) -> R

Source§

impl<R, A6, A7, A8> PessimizeCast for fn(A6, A7, A8) -> R

Source§

impl<R, A7, A8> PessimizeCast for fn(A7, A8) -> R

Source§

impl<R, A8> PessimizeCast for fn(A8) -> R

Source§

impl<T> PessimizeCast for Vec<T>

Available on crate feature alloc only.
Source§

impl<T> PessimizeCast for Empty<T>

Source§

type Pessimized = ()

Source§

fn into_pessimize(self)

Source§

unsafe fn from_pessimize(inner: ()) -> Self

Source§

impl<T> PessimizeCast for PhantomData<T>

Source§

type Pessimized = ()

Source§

fn into_pessimize(self)

Source§

unsafe fn from_pessimize(inner: ()) -> Self

Source§

impl<T> PessimizeCast for AtomicPtr<T>

Available on target_has_atomic="ptr" only.
Source§

impl<T: Clone + Pessimize> PessimizeCast for Repeat<T>

Source§

type Pessimized = T

Source§

fn into_pessimize(self) -> T

Source§

unsafe fn from_pessimize(inner: T) -> Self

Source§

impl<T: Pessimize> PessimizeCast for [T; 1]

Source§

type Pessimized = T

Source§

fn into_pessimize(self) -> T

Source§

unsafe fn from_pessimize(inner: T) -> Self

Source§

impl<T: Pessimize> PessimizeCast for UnsafeCell<T>

Source§

type Pessimized = T

Source§

fn into_pessimize(self) -> T

Source§

unsafe fn from_pessimize(inner: T) -> Self

Source§

impl<T: Pessimize> PessimizeCast for Reverse<T>

Source§

type Pessimized = T

Source§

fn into_pessimize(self) -> T

Source§

unsafe fn from_pessimize(inner: T) -> Self

Source§

impl<T: Pessimize> PessimizeCast for Once<T>

Source§

type Pessimized = T

Source§

fn into_pessimize(self) -> T

Source§

unsafe fn from_pessimize(inner: T) -> Self

Source§

impl<T: Pessimize> PessimizeCast for ManuallyDrop<T>

Source§

type Pessimized = T

Source§

fn into_pessimize(self) -> T

Source§

unsafe fn from_pessimize(inner: T) -> Self

Source§

impl<T: Pessimize> PessimizeCast for Wrapping<T>

Source§

type Pessimized = T

Source§

fn into_pessimize(self) -> T

Source§

unsafe fn from_pessimize(inner: T) -> Self

Source§

impl<T: Pessimize> PessimizeCast for AssertUnwindSafe<T>

Source§

type Pessimized = T

Source§

fn into_pessimize(self) -> T

Source§

unsafe fn from_pessimize(inner: T) -> Self

Source§

impl<T: ?Sized + Unpin, P: Deref<Target = T> + Pessimize> PessimizeCast for Pin<P>

Source§

type Pessimized = P

Source§

fn into_pessimize(self) -> P

Source§

unsafe fn from_pessimize(p: P) -> Self

Source§

impl<T: ?Sized> PessimizeCast for *mut T

Source§

impl<T: ?Sized> PessimizeCast for Box<T>

Available on crate feature alloc only.
Source§

impl<T: ?Sized> PessimizeCast for NonNull<T>

Implementors§