bare::mem
On this page
raw memory operations, Pod and bit casts.
A bit cast goes through a scratch block outside the GC (a generic
value has no address of its own): the value is stored there as A
and loaded as B, with nothing in between that could collect.
reinterpret checks the sizes when called (a where sizeof::<A>() == sizeof::<B>() bound has no compile-time form).
Structs
GcBufSource
pub struct GcBuf<T>One GC reference to an object holding a run of Ts. Compiler-known:
its functions are intrinsics (unchecked indexing) whose bodies never
run.
buf_new: a zeroed buffer oflenelements.buf_get: elementi. UB wheniis out of bounds.buf_set: storevati. UB wheniis out of bounds.
MaybeUninitSource
pub struct MaybeUninit<T>A T that may not be initialized yet: same size and
alignment as T, and as_mut_ptr points at the variable itself.
Its bits start zeroed (uninit is zeroed: a GC reference in it is
null until written, never garbage).
A
MaybeUninitnot written yet; its bits are zero (zeroed).A
MaybeUninitwith every byte zero. Panics when out of memory.An initialized
value.Store
value, overwriting what was there without dropping it.A pointer to this variable's
T(the receiver must be a place).A writable pointer to this variable's
T(the receiver must be a place); write through it to initialize.The value; UB unless it was initialized (
write,new, or throughas_mut_ptr).
Trait implementations 1
impl<T> Debug for MaybeUninit<T>
Traits
PodSource
pub unsafe trait PodPlain old data: every bit pattern of the type is a valid value, its
layout is fixed and it has no Drop. User structs opt
in with #[derive(Pod)] (#[repr(C)] / #[repr(transparent)]); a
hand-written impl is unsafe impl Pod.
bool and char are not Pod: most of their bit patterns are not
values (read a u8 / u32 and convert).
Functions
size_ofSource
pub fn size_of<T>() -> usize Size of T in bytes. A value's size at run time is
x.size_of_val() (Reflect).
align_ofSource
pub fn align_of<T>() -> usize Alignment of T in bytes.
buf_newSource
pub unsafe fn buf_new<T>(len: usize) -> GcBuf<T> A zeroed buffer of len elements; T comes from the slot's type.
buf_getSource
pub unsafe fn buf_get<T>(buf: GcBuf<T>, i: usize) -> T Element i (no bounds check).
buf_setSource
pub unsafe fn buf_set<T>(buf: GcBuf<T>, i: usize, v: T) Store element i (no bounds check).
buf_sameSource
pub fn buf_same<T>(a: GcBuf<T>, b: GcBuf<T>) -> bool Whether a and b are one buffer (identity, not contents). Pins
nothing.
reinterpretSource
pub fn reinterpret<A: Pod, B: Pod>(a: A) -> B The bits of a as a B; both are Pod and the same size (a size
mismatch panics).
transmute_uncheckedSource
pub unsafe fn transmute_unchecked<A, B>(a: A) -> B The bits of a as a B, unchecked: validity, size and the GC
references inside are the caller's problem.
readSource
pub unsafe fn read<T>(src: ConstPtr<T>) -> T The T at src. UB unless it points at a live, initialized T.
writeSource
pub unsafe fn write<T>(dst: Ptr<T>, value: T) Store value at dst without reading or dropping the old one. UB
unless dst is writable T memory.
copySource
pub unsafe fn copy<T>(src: ConstPtr<T>, dst: Ptr<T>, count: usize) Copy count Ts; the ranges may overlap.
copy_nonoverlappingSource
pub unsafe fn copy_nonoverlapping<T>(src: ConstPtr<T>, dst: Ptr<T>, count: usize) Copy count Ts between ranges that do not overlap.
write_bytesSource
pub unsafe fn write_bytes<T>(dst: Ptr<T>, value: u8, count: usize) Set count * size_of::<T>() bytes at dst to value.
swapSource
pub unsafe fn swap<T>(a: Ptr<T>, b: Ptr<T>) Swap the Ts at a and b; they may be the same place.
replaceSource
pub unsafe fn replace<T>(dst: Ptr<T>, value: T) -> T Store value at dst and return what was there.
drop_in_placeSource
pub unsafe fn drop_in_place<T>(p: Ptr<T>) Run the Drop of the T at p (and of its fields'); the memory
stays.