Struct Assume
struct Assume { ... }
Configurable proof assumptions of TransmuteFrom.
When false, the respective proof obligation belongs to the compiler. When
true, the onus of the safety proof belongs to the programmer.
Fields
alignment: boolWhen
false,TransmuteFromis not implemented for transmutations that might violate the alignment requirements of references; e.g.:#![feature(transmutability)] use core::mem::TransmuteFrom; assert_eq!(align_of::<[u8; 2]>(), 1); assert_eq!(align_of::<u16>(), 2); let src: &[u8; 2] = &[0xFF, 0xFF]; // SAFETY: No safety obligations. let dst: &u16 = unsafe { <_ as TransmuteFrom<_>>::transmute(src) };When
true,TransmuteFromassumes that you have ensured that references in the transmuted value satisfy the alignment requirements of their referent types; e.g.:use ; let src: & = &; let maybe_dst: = if <*const _>is_aligned_to else ; assert!;lifetimes: boolWhen
false,TransmuteFromis not implemented for transmutations that extend the lifetimes of references.When
true,TransmuteFromassumes that you have ensured that references in the transmuted value do not outlive their referents.safety: boolWhen
false,TransmuteFromis not implemented for transmutations that might violate the library safety invariants of the destination type; e.g.:#![feature(transmutability)] use core::mem::TransmuteFrom; let src: u8 = 3; struct EvenU8 { // SAFETY: `val` must be an even number. val: u8, } // SAFETY: No safety obligations. let dst: EvenU8 = unsafe { <_ as TransmuteFrom<_>>::transmute(src) };When
true,TransmuteFromassumes that you have ensured that undefined behavior does not arise from using the transmuted value; e.g.:use ; let src: u8 = 42; let maybe_dst: = if src % 2 == 0 else ; assert!;validity: boolWhen
false,TransmuteFromis not implemented for transmutations that might violate the language-level bit-validity invariant of the destination type; e.g.:#![feature(transmutability)] use core::mem::TransmuteFrom; let src: u8 = 3; // SAFETY: No safety obligations. let dst: bool = unsafe { <_ as TransmuteFrom<_>>::transmute(src) };When
true,TransmuteFromassumes that you have ensured that the value being transmuted is a bit-valid instance of the transmuted value; e.g.:use ; let src: u8 = 1; let maybe_dst: = if src == 0 || src == 1 else ; assert_eq!;
Implementations
impl Assume
const fn and(self: Self, other_assumptions: Self) -> SelfCombine the assumptions of
selfandother_assumptions.This is especially useful for extending
Assumein generic contexts; e.g.:use ; /// Attempts to transmute `src` to `&Dst`. /// /// Returns `None` if `src` violates the alignment requirements of `&Dst`. /// /// # Safety /// /// The caller guarantees that the obligations required by `ASSUME`, except /// alignment, are satisfied. unsafe let src: & = &; // SAFETY: No safety obligations. let maybe_dst: = unsafe > };const fn but_not(self: Self, other_assumptions: Self) -> SelfRemove
other_assumptionsthe obligations ofself; e.g.:use Assume; let assumptions = ALIGNMENT.and; let to_be_removed = SAFETY.and; assert_eq!;
impl Add for Assume
fn add(self: Self, other_assumptions: Assume) -> Assume
impl Clone for Assume
fn clone(self: &Self) -> Assume
impl ConstParamTy_ for Assume
impl Copy for Assume
impl Debug for Assume
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Eq for Assume
impl Freeze for Assume
impl PartialEq for Assume
fn eq(self: &Self, other: &Assume) -> bool
impl RefUnwindSafe for Assume
impl Send for Assume
impl StructuralPartialEq for Assume
impl Sub for Assume
fn sub(self: Self, other_assumptions: Assume) -> Assume
impl Sync for Assume
impl Unpin for Assume
impl UnsafeUnpin for Assume
impl UnwindSafe for Assume
impl<T> Any for Assume
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Assume
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Assume
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Assume
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Assume
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Assume
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Assume
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Assume
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>