Function optimization_barrier
pub fn optimization_barrier<T: ?Sized>(val: &T)
Observe the referenced data and prevent the compiler from removing previous writes to it.
This function acts like core::hint::black_box but takes a reference and
does not return the passed value.
It's implemented using the [core::arch::asm!] macro on target arches where asm! is stable,
i.e. aarch64, arm, arm64ec, loongarch64, riscv32, riscv64, s390x, x86, and
x86_64.
On all other targets it's implemented using core::hint::black_box and custom black_box
implemented using #[inline(never)] and read_volatile.
Examples
use NonZeroU32;
use ;
# type ThirdPartyType = u32;
;
let mut data = DataToZeroize ;
// data gets zeroized when dropped
Note that erasure of ThirdPartyType demonstrated above can be fragile if it contains
MaybeUninit or union data. It also does not perform erasure of types like Box or Vec.