mem
import std::core::mem; · source
Free Functions
Memory utilities
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. |
function copy<T>(dest: T*, src: T*, count: u64) -> void;
function copy<T>(dest: T*, src: T*, count: u64) -> void;Copy count values of type T from src to dest. Regions must not overlap.
function copy_overlapping<T>(dest: T*, src: T*, count: u64) -> void;
function copy_overlapping<T>(dest: T*, src: T*, count: u64) -> void;Copy count values from src to dest, correctly handling overlap.
function zero<T>(dest: T*, count: u64) -> void;
function zero<T>(dest: T*, count: u64) -> void;Zero count values of type T starting at dest.
function swap<T>(a: T*, b: T*) -> void;
function swap<T>(a: T*, b: T*) -> void;Swap the values at a and b.
function offset<T>(ptr: T*, count: i64) -> T*;
function offset<T>(ptr: T*, count: i64) -> T*;Offset a typed pointer by count elements (not bytes). Negative values walk backwards.
function align_up(ptr: void*, alignment: u64) -> void*;
function align_up(ptr: void*, alignment: u64) -> void*;Round ptr up to the next multiple of alignment. alignment must be a power of two.
function align_down(ptr: void*, alignment: u64) -> void*;
function align_down(ptr: void*, alignment: u64) -> void*;Round ptr down to the previous multiple of alignment.
function is_aligned(ptr: void*, alignment: u64) -> boolean;
function transmute<From, To>(value: From) -> To;
function transmute<From, To>(value: From) -> To;Reinterpret the bytes of value as a To. Aborts if the two types have different sizes. Bit-pattern validity is the caller's problem.
function drop<T>(_v: T) -> void;
function drop<T>(_v: T) -> void;Explicitly drop a value of type T. This is a no-op for types that do not implement a destructor. The caller is responsible for ensuring that any resources held by _v are properly released if necessary.
import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
function copy<T>(dest: T*, src: T*, count: u64) -> voidCopy count values of type T from src to dest. Regions must not overlap.
function copy_overlapping<T>(dest: T*, src: T*, count: u64) -> voidCopy count values from src to dest, correctly handling overlap.
function zero<T>(dest: T*, count: u64) -> voidZero count values of type T starting at dest.
function offset<T>(ptr: T*, count: i64) -> T*Offset a typed pointer by count elements (not bytes). Negative values walk backwards.
function align_up(ptr: void*, alignment: u64) -> void*Round ptr up to the next multiple of alignment. alignment must be a power of two.
function align_down(ptr: void*, alignment: u64) -> void*Round ptr down to the previous multiple of alignment.
function is_aligned(ptr: void*, alignment: u64) -> booleanfunction transmute<From, To>(value: From) -> ToReinterpret the bytes of value as a To. Aborts if the two types have different sizes. Bit-pattern validity is the caller's problem.
function drop<T>(_v: T) -> voidExplicitly drop a value of type T. This is a no-op for types that do not implement a destructor. The caller is responsible for ensuring that any resources held by _v are properly released if necessary.
function name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
function copy<T>(dest: T*, src: T*, count: u64) -> voidCopy count values of type T from src to dest. Regions must not overlap.
type parameter T(parameter) dest: T*(parameter) src: T*(parameter) count: u64function copy_overlapping<T>(dest: T*, src: T*, count: u64) -> voidCopy count values from src to dest, correctly handling overlap.
function zero<T>(dest: T*, count: u64) -> voidZero count values of type T starting at dest.
function swap<T>(a: T*, b: T*) -> voidSwap the values at a and b.
(parameter) a: T*(parameter) b: T*function offset<T>(ptr: T*, count: i64) -> T*Offset a typed pointer by count elements (not bytes). Negative values walk backwards.
(parameter) ptr: T*(parameter) count: i64function align_up(ptr: void*, alignment: u64) -> void*Round ptr up to the next multiple of alignment. alignment must be a power of two.
(parameter) ptr: void*(parameter) alignment: u64function align_down(ptr: void*, alignment: u64) -> void*Round ptr down to the previous multiple of alignment.
function is_aligned(ptr: void*, alignment: u64) -> booleanfunction transmute<From, To>(value: From) -> ToReinterpret the bytes of value as a To. Aborts if the two types have different sizes. Bit-pattern validity is the caller's problem.
type parameter Fromtype parameter To(parameter) value: Fromfunction drop<T>(_v: T) -> voidExplicitly drop a value of type T. This is a no-op for types that do not implement a destructor. The caller is responsible for ensuring that any resources held by _v are properly released if necessary.
(parameter) _v: T