rok::bare::ptr
rok::bare::ptr - raw pointers (stdlib spec 1.1). A pointer is its
address; reading / writing through it is unsafe (refs-lang 4.15.2).
Provenance is not tracked at run time: expose_provenance /
from_exposed_provenance are the address itself, and the latter is
unsafe (it makes a pointer out of a plain integer). Ptr /
ConstPtr / ManyPtr are never null: #[niche(0)] makes
Ptr<T> | none one address, null = none (spec 2.7.2).
Structs
Ptr
pub struct Ptr<T>A non-null, mutable pointer to one T (C T*).
pub const fn dangling() -> Ptr<T>Well aligned, never dereferenceable.
pub fn null() -> Ptr<T> | noneAlways
none(aPtris never null).pub const fn addr(self) -> usizeThe address (provenance is lost).
pub const fn with_addr(self, addr: usize) -> Ptr<T>pub const fn map_addr(self, f: fn(usize) -> usize) -> Ptr<T>pub fn offset(self, count: isize) -> Ptr<T>countelements further (count * size_of::<T>()bytes).pub const fn add(self, count: usize) -> Ptr<T>pub const fn sub(self, count: usize) -> Ptr<T>pub fn byte_offset(self, count: isize) -> Ptr<T>countbytes further.pub const fn distance(self, origin: Ptr<T>) -> isizeself.addr() - origin.addr()in elements.pub const fn is_aligned(self) -> boolpub const fn align_offset(self, align: usize) -> usizeElements to
addso the address is a multiple ofalign, orusize::MAXwhen no element count gets there.pub const fn cast<U>(self) -> Ptr<U>The same address as a pointer to
U(alignment is the caller's).pub const fn as_const(self) -> ConstPtr<T>pub const fn as_many(self) -> ManyPtr<T>pub unsafe fn read(self) -> TThe
Tit points at. UB unless it points at a live, initializedT.pub unsafe fn write(self, value: T)Store
valuewhere it points. UB unless that is writableTmemory.pub unsafe fn read_volatile(self) -> Tpub unsafe fn write_volatile(self, value: T)
Trait implementations 2
impl<T> !Send for Ptr<T>impl<T> !Sync for Ptr<T>
ConstPtr
pub struct ConstPtr<T>A non-null pointer to one T that is only read (C const T*).
pub const fn dangling() -> ConstPtr<T>pub const fn addr(self) -> usizepub const fn with_addr(self, addr: usize) -> ConstPtr<T>pub fn offset(self, count: isize) -> ConstPtr<T>pub const fn add(self, count: usize) -> ConstPtr<T>pub fn sub(self, count: usize) -> ConstPtr<T>pub fn cast<U>(self) -> ConstPtr<U>pub fn as_many(self) -> ManyPtr<T>pub unsafe fn read(self) -> Tpub unsafe fn read_volatile(self) -> T
Trait implementations 2
impl<T> !Send for ConstPtr<T>impl<T> !Sync for ConstPtr<T>
ManyPtr
pub struct ManyPtr<T>A pointer to a run of Ts of unknown length (C T* array).
pub const fn addr(self) -> usizepub fn with_addr(self, addr: usize) -> ManyPtr<T>pub fn offset(self, count: isize) -> ManyPtr<T>pub fn add(self, count: usize) -> ManyPtr<T>pub const fn as_one(self) -> Ptr<T>The first element as a single-element pointer.
pub fn as_const(self) -> ConstPtr<T>pub unsafe fn read(self, idx: usize) -> TElement
idx(no bounds: the caller knows the length).pub unsafe fn write(self, idx: usize, value: T)pub unsafe fn slice(self, len: usize) -> Slice<T>The
lenTs from here as aSlice<T>; they must stay valid while the view is used, and the GC neither traces nor moves them (elements holding GC references are UB here).
Trait implementations 2
impl<T> !Send for ManyPtr<T>impl<T> !Sync for ManyPtr<T>
CPtr
pub struct CPtr<T>A C-compatible nullable pointer (T* that may be NULL).
pub const fn null() -> CPtr<T>pub fn from_ptr(p: Ptr<T>) -> CPtr<T>pub const fn from_const(p: ConstPtr<T>) -> CPtr<T>pub const fn from_addr(addr: usize) -> CPtr<T>pub const fn is_null(self) -> boolpub const fn addr(self) -> usizepub const fn as_ptr(self) -> Ptr<T> | nonenonewhen null.pub fn as_const(self) -> ConstPtr<T> | none
Trait implementations 2
impl<T> !Send for CPtr<T>impl<T> !Sync for CPtr<T>
Functions
size_of
pub fn size_of<T>() -> usizeSize of T in bytes (also rok::bare::mem::size_of).
align_of
pub fn align_of<T>() -> usizeAlignment of T in bytes.
ptr_cast
pub const fn ptr_cast<UThe same address as a pointer to U (spec 1.2.2: ptr_cast::<U>(p);
alignment is the caller's problem).
align_cast
pub const fn align_cast<T>(p: Ptr<u8>) -> Ptr<T> | nonep as a Ptr<T> when its address suits T's alignment (1.2.3).
align_cast_unchecked
pub const fn align_cast_unchecked<T>(p: Ptr<u8>) -> Ptr<T>p as a Ptr<T> with no alignment check, not even in debug builds
(1.2.3).
const_cast
pub const fn const_cast<T>(p: ConstPtr<T>) -> Ptr<T>Drop the const (1.2.4): writing through the result is the caller's
responsibility.
expose_provenance
pub const fn expose_provenance<T>(p: Ptr<T>) -> usizeThe address of p, marked as escaping (1.1.2 strict provenance).
addr_of
pub fn addr_of<T>(place: T) -> Ptr<T>A pointer to place itself (a local, or a field / array element of
one), valid while that local is in scope: the local lives in memory
and, holding GC references, stays a GC root (whose referents never
move) until its scope ends.
many_addr_of
pub fn many_addr_of<T>(place: T) -> ManyPtr<T>addr_of as the start of a run of Ts (many_addr_of(buf[0])).
Constants
unsafe
pub const unsafe fn from_exposed_provenance<T>(addr: usize) -> Ptr<T>A pointer at addr, assumed to carry an exposed provenance.