Stdlibcore
mem
import std::core::mem; · source
Memory utilities
function copy<T>(dest: T*, src: T*, count: u64) -> void;
function copy_overlapping<T>(dest: T*, src: T*, count: u64) -> void;
function zero<T>(dest: T*, count: u64) -> void;
function swap<T>(a: T*, b: T*) -> void;
function offset<T>(ptr: T*, count: i64) -> T*;
function align_up(ptr: void*, alignment: u64) -> void*;
function align_down(ptr: void*, alignment: u64) -> void*;
function is_aligned(ptr: void*, alignment: u64) -> boolean;
function transmute<From, To>(value: From) -> To;
function drop<T>(_v: T) -> void;
core::mem is typed wrappers over the memory intrinsics. Everything operates on pointers you already hold; nothing here allocates.
| Function | Effect |
|---|---|
copy | Copy count values. Regions must not overlap. |
copy_overlapping | Same, handling overlap correctly. |
zero | Zero count values. |
swap | Swap the two values. |
offset | Step by elements, not bytes. Negative walks backwards. |
align_up / align_down | Round to a power-of-two boundary. |
is_aligned | boolean |
transmute | Reinterpret the bytes. Aborts if the sizes differ; bit-pattern validity is your problem. |
drop | Take ownership of a value and end its scope now. The compiler's synthesised drop runs on the way out; for a type with no destructor it is a no-op. |