Skip to content

stdlib.ptr

Pointer Utilities

Generated from v0.60.1. 1 source files, 19 documented symbols.

ptr.xi

fn null[T]() -> *T

Null pointer of type *T (escape hatch; never dereference).

  • Precondition: true

fn null_mut[T]() -> *T

Null pointer of type *mut T (escape hatch; never dereference).

  • Precondition: true

fn dangling[T]() -> *T

Non-null marker pointer that must never be dereferenced.

  • Precondition: true

fn is_null[T](ptr: *T) -> Bool

True when ptr is a null pointer.

fn read[T](ptr: *T) -> T

Read the value at ptr; requires a non-null, valid pointer.

  • Precondition: ptr != null

fn write[T](ptr: *T, value: T)

Write value to ptr; requires a non-null, valid pointer.

  • Precondition: ptr != null

fn read_volatile[T](ptr: *T) -> T

Volatile read at ptr (no elision/reordering by the backend).

  • Precondition: ptr != null

fn write_volatile[T](ptr: *T, value: T)

Volatile write of value to ptr.

  • Precondition: ptr != null

fn swap[T](a: *T, b: *T)

Swap the values at a and b; both must be non-null and valid.

  • Precondition: a != null
  • Precondition: b != null

fn replace[T](dest: *T, src: T) -> T

Replace *dest with src, returning the previous value.

  • Precondition: dest != null
  • Postcondition: result == old_value

fn copy[T](src: *T, dst: *T, count: Int)

Copy count values from src to dst; ranges may overlap.

  • Precondition: src != null
  • Precondition: dst != null
  • Precondition: count > 0

fn copy_nonoverlapping[T](src: *T, dst: *T, count: Int)

Copy count values from src to dst; ranges must not overlap.

  • Precondition: src != null
  • Precondition: dst != null
  • Precondition: count > 0

fn eq[T](a: *T, b: *T) -> Bool

Pointer equality (address comparison).

fn offset[T](ptr: *T, count: Int) -> *T

Pointer arithmetic: ptr + count elements.

  • Precondition: ptr != null

fn wrapping_offset[T](ptr: *T, count: Int) -> *T

Wrapping pointer arithmetic (no in-bounds requirement).

  • Precondition: true

fn add[T](ptr: *T, count: Int) -> *T

ptr + count elements; requires a non-null pointer.

  • Precondition: ptr != null

fn sub[T](ptr: *T, count: Int) -> *T

ptr - count elements; requires a non-null pointer.

  • Precondition: ptr != null

fn from_ref[T](r: &T) -> *T

Convert a shared reference to a raw pointer (escape hatch).

  • Precondition: true

fn from_mut[T](r: &mut T) -> *T

Convert a mutable reference to a raw mutable pointer (escape hatch).

  • Precondition: true