rok::bare::mem
rok::bare::mem - raw memory operations, Pod and bit casts (stdlib
spec 1.2.5 / 1.2.6 / 1.3).
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 (the spec's where sizeof::<A>() == sizeof::<B>() has no compile-time form yet).
Re-exports
rok::bare::ptr::
pub use rok::bare::ptr::Structs
GcBuf
pub struct GcBuf<T>pub const unsafe fn new(len: usize) -> GcBuf<T>pub const unsafe fn get(self, i: usize) -> Tpub const unsafe fn set(self, i: usize, v: T)
MaybeUninit
pub struct MaybeUninit<T>A T that may not be initialized yet (spec 1.3.2): 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).
pub fn uninit() -> MaybeUninit<T>pub fn zeroed() -> MaybeUninit<T>pub const fn new(value: T) -> MaybeUninit<T>pub const fn write(ref self, value: T)pub fn as_ptr(self) -> ConstPtr<T>A pointer to this variable's
T(the receiver must be a place).pub fn as_mut_ptr(ref self) -> Ptr<T>pub const unsafe fn assume_init(self) -> TThe value; UB unless it was initialized (
write,new, or throughas_mut_ptr).
Traits
Pod
pub trait PodPlain old data: every bit pattern of the type is a valid value, its
layout is fixed and it has no Drop (spec 1.3.3). User structs opt
in with #[derive(Pod)] (#[repr(C)] / #[repr(transparent)]).
Functions
buf_new
pub unsafe fn buf_new<T>(len: usize) -> GcBuf<T>A zeroed buffer of len elements; T comes from the slot's type.
buf_get
pub unsafe fn buf_get<T>(buf: GcBuf<T>, i: usize) -> TElement i (no bounds check).
buf_set
pub unsafe fn buf_set<T>(buf: GcBuf<T>, i: usize, v: T)Store element i (no bounds check).
buf_same
pub fn buf_same<T>(a: GcBuf<T>, b: GcBuf<T>) -> boolWhether a and b are one buffer (identity, not contents). Pins
nothing.
reinterpret
pub fn reinterpret<A: PodThe bits of a as a B; both are Pod and the same size (a size
mismatch panics).
transmute_unchecked
pub unsafe fn transmute_unchecked<AThe bits of a as a B, unchecked: validity, size and the GC
references inside are the caller's problem.
size_of_val
pub const fn size_of_val<T>(val: T) -> usizeSize of T (the value's own type; rok has no unsized values yet).
align_of_val
pub const fn align_of_val<T>(val: T) -> usizemin_align_of
pub const fn min_align_of<T>() -> usizeread
pub unsafe fn read<T>(src: ConstPtr<T>) -> Twrite
pub unsafe fn write<T>(dst: Ptr<T>, value: T)read_volatile
pub unsafe fn read_volatile<T>(src: ConstPtr<T>) -> Twrite_volatile
pub unsafe fn write_volatile<T>(dst: Ptr<T>, value: T)copy
pub unsafe fn copy<T>(src: ConstPtr<T>, dst: Ptr<T>, count: usize)Copy count Ts; the ranges may overlap.
copy_nonoverlapping
pub unsafe fn copy_nonoverlapping<T>(src: ConstPtr<T>, dst: Ptr<T>, count: usize)Copy count Ts between ranges that do not overlap.
write_bytes
pub unsafe fn write_bytes<T>(dst: Ptr<T>, value: u8, count: usize)Set count * size_of::<T>() bytes at dst to value.
swap
pub unsafe fn swap<T>(a: Ptr<T>, b: Ptr<T>)replace
pub unsafe fn replace<T>(dst: Ptr<T>, value: T) -> TStore value at dst and return what was there.
drop_in_place
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.