Skip to content
CryoCryo home
StdlibFoundations

core

core is the bottom of the library. It neither allocates nor performs I/O, and everything above it is built from what lives here. Much of the language is defined against these declarations: a..b builds a Range, for-in drives an Iterator, a < b on a user type calls Ord::compare, and [T] iteration hands you a Slice<T>.

public module core::intrinsics;
public module core::primitives;
public module core::option;
public module core::result;
public module core::panic_unwind;
public module core::slice;
public module core::ptr;
public module core::mem;
public module core::marker;
public module core::clone;
public module core::default;
public module core::cmp;
public module core::convert;
public module core::iter;
public module core::ops;
public module core::hash;
public module core::drop;
public module core::varargs;

Most of core is in the prelude already. Option, Result, Slice, Range, Iterator, the panic helpers, the primitive methods, and the traits the compiler reasons about by identity — Drop, Copy, Send, Sync, Eq, Ord, Clone — all resolve without an import. The rest you import explicitly.

FileWhat it holdsImport
optionOption<T>(prelude)
resultResult<T, E>(prelude)
sliceSlice<T>, the borrowed contiguous view(prelude)
ptrNonNull<T>import std::core::ptr;
iterIterator and its adapters(prelude)
opsRange, RangeInclusive, Step, and the operator traits(prelude)
cmpOrdering, Eq, Ord, min, max, clamp(prelude)
convertFrom, Into, TryFrom, TryInto, ConversionErrorimport std::core::convert;
hashHash, Hasher, DefaultHasher, Fnv128Hasherimport std::core::hash;
markerCopy, Send, Sync(prelude)
cloneClone(prelude)
defaultDefaultimport std::core::default;
dropDrop(prelude)
memcopy, zero, swap, transmute, the alignment helpersimport std::core::mem;
panic_unwindcatch_unwind, PanicInfoimport std::core::panic_unwind;
primitivesMethods on i32, char, string, ...(prelude)
varargsVaArgs, the args... bucket(prelude)
intrinsicsThe compiler-lowered primitives everything else is built on(prelude)

Panicking

These four live at the root of core (std::core), which is in the prelude. panic is typed never, so the compiler treats the call as divergent structurally rather than special-casing the symbol name; it forwards to the panic intrinsic.

FunctionBehaviour
panicAbort with the message and source location.
assertPanic when the condition is false. Always checked.
unreachableFor a path you believe cannot be taken.
todoFor a function you have not written yet.

Pass the compiler-provided FILE and LINE to panic; the helpers do it for you. To catch a panic instead of aborting, see panic_unwind.

function panic(message: string, loc: intrinsics::Location) -> never;

Panic with message, reporting the place loc: intrinsics::location() written at the call, or in a ![caller_location] function its caller's. The helpers below do that automatically.

function assert(condition: boolean, message: string) -> void;

Panic if condition is false. Always checked.

function unreachable() -> never;

Mark a code path the programmer believes cannot be reached. If it ever is, the program aborts with a clear message rather than executing wrong code.

function todo() -> never;

Stub a function you'll implement later. Reading better than inlining panic("not yet implemented", ...) with the place is its whole job.