Skip to content

stdlib.mem

Memory Utilities

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

mem.xi

fn swap[T](a: &mut T, b: &mut T)

Swap two values in place.

  • Precondition: true
  • Postcondition: a == b@pre && b == a@pre

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

Replace *dest with src, returning the previous value.

  • Precondition: true
  • Postcondition: result == dest@pre

fn take[T](dest: &mut T) -> T

Replace with the default value and return the previous one.

  • Postcondition: true

fn drop[T](value: T)

Drop a value (explicit destructor call).

  • Postcondition: true

fn size_of[T]() -> Int

Size queries Compiler intrinsic -- requires compiler support

  • Postcondition: result > 0

fn align_of[T]() -> Int

Compiler intrinsic -- requires compiler support

  • Postcondition: result > 0

fn size_of_val[T](value: &T) -> Int

Size of the pointed-to value in bytes.

  • Postcondition: result > 0
  • Postcondition: result == size_of()

fn min_align_of_val[T](value: &T) -> Int

Minimum alignment of the pointed-to value in bytes.

  • Postcondition: result > 0
  • Postcondition: result == align_of()

fn zeroed[T]() -> T

Zeroed memory -- all bytes set to zero

  • Postcondition: true

fn uninitialized[T]() -> T

Uninitialized memory (unsafe -- reading before writing is UB)

  • Postcondition: true

type ManuallyDrop

Manually drop (defer cleanup)

Field Type
value T

fn new[T](value: T) -> ManuallyDrop[T]

Wrap a value that must not be dropped automatically.

fn into_inner[T](self: Self) -> T

Take the value out (no destructor run).

  • Precondition: true

fn take[T](self: Self) -> T

Take the value out, leaving the slot uninitialized.

  • Precondition: true
  • Postcondition: true

fn drop[T](self: Self)

Destroy the wrapper without dropping the value.

  • Precondition: true
  • Postcondition: true

fn mem_copy(dst: *UInt8, src: *UInt8, n: UInt) -> *UInt8

Copy n bytes from src to dst using the SSE/AVX-accelerated runtime memcpy. dst and src must point to valid, non-overlapping buffers of at least n bytes (use mem_move for overlapping regions). Returns dst. Complexity: O(n), SIMD-vectorized.

  • Precondition: true

fn mem_set(s: *UInt8, c: Int32, n: UInt) -> *UInt8

Fill n bytes at s with byte value c using the accelerated runtime memset. Returns s. Complexity: O(n), SIMD-vectorized.

  • Precondition: true

fn mem_compare(a: *UInt8, b: *UInt8, n: UInt) -> Int32

Compare two byte buffers of length n (lexicographic byte order). Returns 0 if equal, <0 if a < b, >0 if a > b. Complexity: O(n), SIMD-vectorized.

  • Precondition: true

fn mem_move(dst: *UInt8, src: *UInt8, n: UInt) -> *UInt8

Copy bytes between possibly-overlapping regions safely. Uses the runtime memmove semantics (handles overlap).

  • Precondition: true