// Object elements — mutate in place through the handle.
for(names, s => {
s.push_str("!");
});
// Consume an iterator chain.
for(list.into_iter(), x => print(x));
// Borrow struct elements in place (read AND write).
for(enemies, inout(e) => {
e.hp = (e.hp - i32(1));
});
Module prelude
Prelude — automatically imported into every Yo source file.
Provides core language primitives: traits (Comptime, Runtime, Clone,
Eq, Ord, Hash, …), fundamental types (Option, Result, Rc,
Slice, Range, String, …), operator traits (Add, Sub, …), type
reflection (TypeInfo), conversion (Into, From), the async runtime
(Io, Future, JoinHandle), and derive rules.
Do NOT import std/prelude — it is loaded automatically and an
explicit import will produce a compile error.
Stability
The prelude is the one module whose surface is a language decision, not a library one: every name here is in scope in every Yo file, so adding one can shadow a user's binding and removing one breaks every program. Treat additions as breaking changes in review even though the compiler will not call them that.
Broadly stable: the core traits (Clone, Eq, Ord, Hash, Dispose,
Send, the operator traits), Option, Result, Rc, Range,
the numeric types and their inherent methods, and the async vocabulary
(Io, Future, JoinHandle). These have Rust's names and meanings and
are not expected to move.
The byte-conversion battery is now ONE blanket impl, not ten copies.
to_be_bytes, to_le_bytes, from_be_bytes and from_le_bytes return
Array(u8, T.BYTES), taking the length from the receiver's own associated
constant, which value substitution in a type position made expressible
(plans/backlog/VALUE_SUBSTITUTION_IN_TYPE_POSITIONS.md). usize and
isize therefore HAVE them now, which they could not before: their width
is the target's, and _USIZE_BYTES derives it the same way _USIZE_BITS
derives the bit width. BYTES is declared through the ByteWidth trait
rather than inherently beside BITS, because an inherent associated
constant does not resolve in a length position
(issues/an-inherent-associated-constant-does-not-resolve-as-an-array-length.md).
This is additive for callers — same names, same meanings — but the methods
are defined in a different place, so a doc link may move.
Types
File-level privilege flag for the pragma(...) builtin. Declared
at the top of a Yo file (e.g. pragma(Pragma.AllowUnsafe);) to
opt the file into compiler-recognized behaviors. See
plans/reference/MEMORY_SAFETY.md.
Variants
| Variant | Fields | Description |
|---|---|---|
AllowUnsafe | File is permitted to use raw pointer ops, | |
AllowMacroDef | File is permitted to DEFINE macro functions — | |
SkipPrelude | Disable the auto-import of | |
SkipWasm | Test-runner directive: skip this test file on ALL WASM targets. | |
SkipWasm32Emscripten | Test-runner directive: skip when target is wasm32-unknown-emscripten. | |
SkipWasm32Wasi | Test-runner directive: skip when target is wasm32-wasip1. | |
SkipWindows | File is skipped by the test runner when the target OS is Windows. For tests that depend on a POSIX-only or not-yet-ported platform facility (e.g. std/crypto/tls needs OpenSSL, absent on the Windows runners — Schannel is the deferred Windows path). Mirrors the SkipWasm32* variants. | |
NeedsLeakVerdict | Test-runner directive: this file's tests only have a failure mode when
the LeakSanitizer verdict is applied — they exercise a construct and
assert values that were never wrong, so a leak is the one defect they
can catch. When the run stages the verdict off ( | |
Verify | Formal verification: contracts in this file are proof obligations. Phase 0 only registers the pragma; later phases will hook in verification. See plans/backlog/FORMAL_VERIFICATION.md. | |
VerifyOrAssert | Formal verification: try to prove, fall back to runtime assert when proof times out. The production mode for verified code. | |
NoContracts | Formal verification: erase contract clauses entirely (no proof, no runtime assert). For release/benchmark builds. | |
StrictBorrow | Strict borrowed loops: inside |
Trait Implementations
Methods
== : (Pragma) fn(lhs : Pragma, rhs : Pragma) -> bool!= : (Pragma) fn(lhs : Pragma, rhs : Pragma) -> bool=== Cycle-GC tracing ===
GcTracer carries the cycle collector's edge-registration callback (an opaque
raw pointer). A Trace impl calls tracer.visit(slot) once per outgoing edge,
passing a POINTER to where the child lives (a struct field or a container buffer
element). The raw callback is never touched directly.
Fields
| Name | Type | Description |
|---|---|---|
_callback | *(u8) |
impl(GcTracer, ...)
visit : (GcTracer) fn(generic(T) self : GcTracer, slot : *(T)) -> unitTrace one outgoing edge. slot points at where the child lives; the collector
reads *slot WITHOUT touching its reference count — registering the edge if it
is a managed handle and recursing inline through value structure otherwise.
Passing the slot pointer (not the element by value) keeps tracing RC-neutral: a
by-value managed handle would be dup'd then dropped, freeing a live element
mid-collection.
Parameters
| Name | Type | Notes |
|---|---|---|
self | GcTracer | |
slot | *(T) |
Returns: unit
The functions behind an Allocator. Implementing one needs
pragma(Pragma.AllowUnsafe).
alloc(ctx, size)returns a block of at leastsizebytes aligned to 16, or.None.realloc(ctx, ptr, new_size)resizes a block this vtable'sallocreturned, keeping its firstmin(old, new_size)bytes..Noneleaves the original block untouched and still owned by the caller.free(ctx, ptr)releases such a block.
There is no size at free and no aligned family: every container buffer
and every RC block uses the plain family (see std/allocator.yo's module notes).
Fields
| Name | Type | Description |
|---|---|---|
alloc | fn(ctx : ?(*(void)), size : usize) -> ?(*(void)) | |
realloc | fn(ctx : ?(*(void)), ptr : ?(*(void)), new_size : usize) -> ?(*(void)) | |
free | fn(ctx : ?(*(void)), ptr : ?(*(void))) -> unit |
An allocator value: an opaque context plus an immortal vtable. Two words, copied freely; it is not reference counted, because an allocator must not itself need an allocator.
Fields
| Name | Type | Description |
|---|---|---|
ctx | ?(*(void)) | |
vtable | *(AllocatorVTable) |
Trait Implementations
impl(Allocator, Send())
impl(Allocator, Sync())
Methods
clone : (Allocator) fn(inout(self) : Allocator) -> Allocatorglobal : (Allocator) fn() -> AllocatorReturns: Allocator
alloc : (Allocator) fn(self : Allocator, size : usize) -> ?(*(void))realloc : (Allocator) fn(ptr : *(void), new_size : usize) -> ?(*(void))Parameters
| Name | Type | Notes |
|---|---|---|
ptr | *(void) | |
new_size | usize |
Returns: ?(*(void))
free : (Allocator) fn(ptr : ?(*(void))) -> unitParameters
| Name | Type | Notes |
|---|---|---|
ptr | ?(*(void)) |
Returns: unit
owner_of : (Allocator) fn(ptr : *(void)) -> Allocatorsame : (Allocator) fn(self : Allocator, other : Allocator) -> boolglobal : (Allocator) fn() -> AllocatorReturns: Allocator
alloc : (Allocator) fn(self : Allocator, size : usize) -> ?(*(void))realloc : (Allocator) fn(ptr : *(void), new_size : usize) -> ?(*(void))Parameters
| Name | Type | Notes |
|---|---|---|
ptr | *(void) | |
new_size | usize |
Returns: ?(*(void))
free : (Allocator) fn(ptr : ?(*(void))) -> unitParameters
| Name | Type | Notes |
|---|---|---|
ptr | ?(*(void)) |
Returns: unit
owner_of : (Allocator) fn(ptr : *(void)) -> AllocatorHalf-open range start..end (excludes end).
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(Range(i8), Iterator(...))
Item : i8next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(i16), Iterator(...))
Item : i16next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(i32), Iterator(...))
Item : i32next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(i64), Iterator(...))
Item : i64next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(isize), Iterator(...))
Item : isizenext : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(u8), Iterator(...))
Item : u8next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(u16), Iterator(...))
Item : u16next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(u32), Iterator(...))
Item : u32next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(u64), Iterator(...))
Item : u64next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(usize), Iterator(...))
Item : usizenext : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(Range(i8), DoubleEndedIterator(...))
Item : i8next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(i16), DoubleEndedIterator(...))
Item : i16next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(i32), DoubleEndedIterator(...))
Item : i32next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(i64), DoubleEndedIterator(...))
Item : i64next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(isize), DoubleEndedIterator(...))
Item : isizenext_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(u8), DoubleEndedIterator(...))
Item : u8next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(u16), DoubleEndedIterator(...))
Item : u16next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(u32), DoubleEndedIterator(...))
Item : u32next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(u64), DoubleEndedIterator(...))
Item : u64next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(Range(usize), DoubleEndedIterator(...))
Item : usizenext_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
Inclusive range start..=end (includes end).
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(RangeInclusive(i8), Iterator(...))
Item : i8next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(i16), Iterator(...))
Item : i16next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(i32), Iterator(...))
Item : i32next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(i64), Iterator(...))
Item : i64next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(isize), Iterator(...))
Item : isizenext : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(u8), Iterator(...))
Item : u8next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(u16), Iterator(...))
Item : u16next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(u32), Iterator(...))
Item : u32next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(u64), Iterator(...))
Item : u64next : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(usize), Iterator(...))
Item : usizenext : (fn(inout(self) : Self) -> Option(i8))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(i8)
impl(RangeInclusive(i8), DoubleEndedIterator(...))
Item : i8next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(i16), DoubleEndedIterator(...))
Item : i16next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(i32), DoubleEndedIterator(...))
Item : i32next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(i64), DoubleEndedIterator(...))
Item : i64next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(isize), DoubleEndedIterator(...))
Item : isizenext_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(u8), DoubleEndedIterator(...))
Item : u8next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(u16), DoubleEndedIterator(...))
Item : u16next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(u32), DoubleEndedIterator(...))
Item : u32next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(u64), DoubleEndedIterator(...))
Item : u64next_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
impl(RangeInclusive(usize), DoubleEndedIterator(...))
Item : usizenext_back : (fn(inout(self) : Self) -> Option(i8))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(i8)
Ordering — result of a comparison.
Variants
| Variant | Fields | Description |
|---|---|---|
Less | Left-hand side is less than right-hand side. | |
Equal | Both sides are equal. | |
Greater | Left-hand side is greater than right-hand side. |
Reverse(T) — a wrapper whose Ord is T's, inverted (Rust's
core::cmp::Reverse).
It turns any max-ordered structure into a min-ordered one without a second
implementation. PriorityQueue is a MAX-heap (D11), so a min-heap is:
pq := PriorityQueue(Reverse(i32)).new();
pq.push(Reverse(i32)(i32(5)));
pq.push(Reverse(i32)(i32(1)));
pq.pop().unwrap().value; // 1 — the SMALLEST
It is equally the way to sort descending: list.sort_by((a, b) -> (Reverse(i32)(a) < Reverse(i32)(b))).
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(generic(T : Type), where(T <: Eq(T)), Reverse(T), Eq(Reverse(T))(...))
impl(generic(T : Type), where(T <: Ord(T)), Reverse(T), Ord(Reverse(T))(...))
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
Trait Implementations
RawSlice — a plain ptr+len pair for PRIVILEGED (pragma'd) code: C interop and std internals. Carries a raw pointer, so the existing raw-pointer gates apply: safe code cannot name or construct it. Replaces the builtin Slice(T) for internal plumbing (plans/archive/SLICE_REWORK.md step 4).
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
ComptimeValue — a data document read at COMPILE time (plans/archive/BUILD_AND_DEPENDENCY_SYSTEM_REDESIGN.md §5.2).
comptime_json_parse and comptime_toml_parse return one of these. No
runtime container can exist at compile time, so the tree is built from
ComptimeList and comptime scalars only.
A table keeps PARALLEL key and value lists, the shape std/encoding/json's
JsonValue.Object and std/encoding/toml's TomlValue.Table already use.
The plan sketched a separate ComptimeEntry struct instead; that shape is
not expressible, because ComptimeEntry.value : ComptimeValue and
ComptimeValue.Table(… ComptimeEntry) are mutually recursive TYPE
definitions and the evaluator rejects those ("cyclic definition"). Parallel
lists need only Self, which is fine. Keys are in document order.
Variants
| Variant | Fields | Description |
|---|---|---|
Null | JSON | |
Bool | v: bool |
|
Int | v: comptime_int | An integer. JSON numbers that are whole become |
Float | v: comptime_float | A non-integral number. |
Str | v: comptime_str |
|
List | items: ComptimeList(ComptimeValue) | An array, in document order. |
Table | keys: ComptimeList(comptime_str), values: ComptimeList(ComptimeValue) | A table/object: |
Trait Implementations
impl(ComptimeValue, Comptime())
impl(ComptimeValue, Acyclic())
impl(ComptimeValue, ...)
get : (ComptimeValue) fn(self : ComptimeValue, key : comptime_str) -> ComptimeValueThe value under key, or .Null when this is not a table or has no such
key. .Null rather than an Option because an Option of a comptime value
is itself awkward to match at compile time, and a missing key and a JSON
null behave the same way for every use this exists for.
Parameters
| Name | Type | Notes |
|---|---|---|
self | ComptimeValue | comptime |
key | comptime_str | comptime |
Returns: ComptimeValue
at : (ComptimeValue) fn(self : ComptimeValue, i : usize) -> ComptimeValueThe element at i, or .Null when this is not a list or i is past its
end.
Parameters
| Name | Type | Notes |
|---|---|---|
self | ComptimeValue | comptime |
i | usize | comptime |
Returns: ComptimeValue
len : (ComptimeValue) fn(self : ComptimeValue) -> usizeThe number of elements of a list, or entries of a table; 0 otherwise.
Parameters
| Name | Type | Notes |
|---|---|---|
self | ComptimeValue | comptime |
Returns: usize
as_str : (ComptimeValue) fn(self : ComptimeValue, fallback : comptime_str) -> comptime_strThe string this holds, or fallback when it holds anything else.
Parameters
| Name | Type | Notes |
|---|---|---|
self | ComptimeValue | comptime |
fallback | comptime_str | comptime |
Returns: comptime_str
as_int : (ComptimeValue) fn(self : ComptimeValue, fallback : comptime_int) -> comptime_intThe integer this holds, or fallback when it holds anything else.
Parameters
| Name | Type | Notes |
|---|---|---|
self | ComptimeValue | comptime |
fallback | comptime_int | comptime |
Returns: comptime_int
as_bool : (ComptimeValue) fn(self : ComptimeValue, fallback : bool) -> boolThe boolean this holds, or fallback when it holds anything else.
Parameters
| Name | Type | Notes |
|---|---|---|
self | ComptimeValue | comptime |
fallback | bool | comptime |
Returns: bool
is_null : (ComptimeValue) fn(self : ComptimeValue) -> boolTrue when this is .Null — a missing key or an explicit JSON null.
Parameters
| Name | Type | Notes |
|---|---|---|
self | ComptimeValue | comptime |
Returns: bool
ExprList
Type reflection metadata structs — used by Type.get_info().
StructKind — discriminant for struct flavors.
Variants
| Variant | Fields | Description |
|---|---|---|
Struct | Regular value struct. | |
Object | Reference-counted object. | |
AtomicObject | Atomic reference-counted object. | |
NewType | Single-field newtype wrapper. |
Trait Implementations
impl(StructKind, Comptime())
TypeFieldInfo — metadata for a single struct/object field.
Fields
| Name | Type | Description |
|---|---|---|
name | comptime_str | Variant name. |
field_type | Type | Field type. |
Trait Implementations
impl(TypeFieldInfo, Comptime())
impl(TypeFieldInfo, ...)
to_expr : (TypeFieldInfo) fn(self : TypeFieldInfo) -> ExprConvert the field name to an AST expression (for metaprogramming).
Parameters
| Name | Type | Notes |
|---|---|---|
self | TypeFieldInfo | comptime |
Returns: Expr
ParamInfo — metadata for a function parameter.
Fields
| Name | Type | Description |
|---|---|---|
name | comptime_str | Variant name. |
param_type | Type | Parameter type. |
is_comptime | bool |
|
is_quote | bool |
|
is_variadic | bool |
|
Trait Implementations
impl(ParamInfo, Comptime())
FunctionInfo — metadata for a function type.
Fields
| Name | Type | Description |
|---|---|---|
params | ComptimeList(ParamInfo) | Regular parameters. |
return_type | Type | Return type. |
forall_params | ComptimeList(ForallParamInfo) | Optional generic parameters for generic types. |
implicit_params | ComptimeList(ImplicitParamInfo) | Implicit |
is_closure | bool |
|
Trait Implementations
impl(FunctionInfo, Comptime())
TraitKind — discriminant for different trait flavors.
Variants
| Variant | Fields | Description |
|---|---|---|
Future | child: Type, effects: ComptimeList(TraitInfo) | A Future trait with child type and effects. |
Fn | call: FunctionInfo | A callable |
Normal | A normal user-defined trait. |
Trait Implementations
impl(TraitKind, Comptime())
VariantInfo — metadata for an enum variant.
Fields
| Name | Type | Description |
|---|---|---|
name | comptime_str | Variant name. |
fields | ComptimeList(TypeFieldInfo) | Variant fields (may be empty for unit variants). |
_enum_type | Type | |
_variant_index | usize |
Trait Implementations
impl(VariantInfo, Comptime())
TypeInfo — compile-time enum representing rich type metadata.
Returned by Type.get_info() for compile-time type reflection.
Variants
| Variant | Fields | Description |
|---|---|---|
Unit | ||
Bool |
| |
Usize | ||
Isize | ||
U8 | ||
I8 | ||
U16 | ||
I16 | ||
U32 | ||
I32 | ||
U64 | ||
I64 | ||
F32 | ||
F64 | ||
Char | ||
Short | ||
UShort | ||
Int | An integer. JSON numbers that are whole become | |
UInt | ||
Long | ||
ULong | ||
LongLong | ||
ULongLong | ||
LongDouble | ||
Void | ||
Str |
| |
Array | element: Type, length: comptime_int | |
Tuple | fields: ComptimeList(TypeFieldInfo) | |
Struct | fields: ComptimeList(TypeFieldInfo), kind: StructKind | Regular value struct. |
Enum | variants: ComptimeList(VariantInfo) | |
Union | fields: ComptimeList(TypeFieldInfo) | |
Function | info: FunctionInfo | |
Ptr | pointee: Type | |
Iso | child: Type | |
Dyn | required_traits: ComptimeList(TraitInfo), negative_traits: ComptimeList(TraitInfo) | |
Trait | fields: ComptimeList(TraitFieldInfo), kind: TraitKind | |
Type | level: comptime_int | |
Some | name: comptime_str, required_traits: ComptimeList(TraitInfo), negative_traits: ComptimeList(TraitInfo), resolved_type: Type | |
ComptimeInt | ||
ComptimeFloat | ||
ComptimeStr | ||
ComptimeList | element: Type | |
Expr | ||
TypeApplication |
Trait Implementations
impl(TypeInfo, Comptime())
impl(TypeInfo, ...)
is_struct : (TypeInfo) fn(self : TypeInfo) -> boolis_enum : (TypeInfo) fn(self : TypeInfo) -> boolis_union : (TypeInfo) fn(self : TypeInfo) -> boolis_tuple : (TypeInfo) fn(self : TypeInfo) -> boolis_array : (TypeInfo) fn(self : TypeInfo) -> boolis_str : (TypeInfo) fn(self : TypeInfo) -> boolis_function : (TypeInfo) fn(self : TypeInfo) -> boolis_pointer : (TypeInfo) fn(self : TypeInfo) -> boolis_trait : (TypeInfo) fn(self : TypeInfo) -> boolis_void : (TypeInfo) fn(self : TypeInfo) -> boolis_primitive : (TypeInfo) fn(self : TypeInfo) -> boolis_integer : (TypeInfo) fn(self : TypeInfo) -> boolis_float : (TypeInfo) fn(self : TypeInfo) -> boolis_comptime : (TypeInfo) fn(self : TypeInfo) -> booltrue if the parameter is compile-time (comptime).
Parameters
| Name | Type | Notes |
|---|---|---|
self | TypeInfo | comptime |
Returns: bool
is_numeric : (TypeInfo) fn(self : TypeInfo) -> boolFieldInfo — compile-time struct field metadata for derive rules (legacy alias).
Fields
| Name | Type | Description |
|---|---|---|
name | comptime_str | Variant name. |
field_type | Type | Field type. |
Trait Implementations
impl(FieldInfo, Comptime())
Option — a value that may or may not be present.
Option(T) has two variants:
.Some(value)— contains a value of typeT.None— contains no value
Example
(x : Option(i32)) = .Some(i32(42));
assert(x.is_some(), "expected Some");
assert(x.unwrap() == i32(42), "expected 42");
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(generic(T : Type), Option(T), ...)
unwrap : (fn(self : Self) -> T)Extract the contained value, panicking with a message if None.
Returns: T
unwrap_or : (fn(self : Self, or_value : T) -> T)Extract the contained value, or return or_value if None.
Returns: T
is_some : (fn(self : Self) -> bool)Return true if the option contains a value.
Returns: bool
is_none : (fn(self : Self) -> bool)Return true if the option is None.
Returns: bool
impl(generic(T : Type), Option(T), ...)
map : (fn(generic(B : Type), self : Self, f : Impl(Fn(a : T) -> B)) -> Option(B))Apply f to the contained value (if Some), or return None.
Returns: Option(B)
and_then : (fn(generic(B : Type), self : Self, f : Impl(Fn(a : T) -> Option(B))) -> Option(B))Apply f to the contained value (if Some) and flatten the result.
Returns: Option(B)
filter : (fn(self : Self, predicate : Impl(Fn(a : T) -> bool)) -> Option(T))Return Some(value) if the predicate returns true, otherwise None.
Returns: Option(T)
or_else : (fn(self : Self, f : Impl(Fn() -> Option(T))) -> Option(T))Return this option if Some, otherwise call f and return its result.
Returns: Option(T)
map_or : (fn(generic(B : Type), self : Self, default_val : B, f : Impl(Fn(a : T) -> B)) -> B)Apply f if Some, otherwise return default_val.
Returns: B
map_or_else : (fn(generic(B : Type), self : Self, default_fn : Impl(Fn() -> B), f : Impl(Fn(a : T) -> B)) -> B)Apply f if Some, otherwise call default_fn.
Returns: B
and : (fn(generic(B : Type), self : Self, optb : Option(B)) -> Option(B))Return optb if self is Some, otherwise None.
Returns: Option(B)
or : (fn(self : Self, optb : Option(T)) -> Option(T))Return self if Some, otherwise return optb.
Returns: Option(T)
unwrap_or_else : (fn(self : Self, f : Impl(Fn() -> T)) -> T)Extract the contained value, or call f to produce a default.
Returns: T
expect : (fn(self : Self, msg : str) -> T)Extract the contained value, panicking with msg if None.
Returns: T
is_some_and : (fn(self : Self, f : Impl(Fn(a : T) -> bool)) -> bool)Return true if Some and the predicate holds for the value.
Returns: bool
inspect : (fn(self : Self, f : Impl(Fn(a : T) -> unit)) -> Option(T))Call f with the contained value (if Some), then return the option.
Returns: Option(T)
impl(generic(T : Type), Option(T), ...)
take : (fn(inout(self) : Self) -> Option(T))Take the value out of the option, leaving None in its place.
Returns: Option(T)
replace : (fn(inout(self) : Self, value : T) -> Option(T))Replace the contained value with Some(value), returning the old option.
Returns: Option(T)
impl(generic(T : Type), Option(Option(T)), ...)
flatten : (fn(self : Self) -> Option(T))Collapse one level of nesting.
Returns: Option(T)
impl(generic(T : Type), Option(T), Default(...))
default : (fn() -> Self)The default value of the type.
Returns: Self
impl(generic(T : Type), where(T <: Default), Option(T), ...)
unwrap_or_default : (fn(self : Self) -> T)Extract the contained value, or T's default when None.
Returns: T
impl(generic(T : Type), where(T <: Comptime), Option(T), Comptime())
impl(generic(T : Type), where(T <: Comptime), Option(T), ...)
comptime_unwrap : (fn(comptime(self) : Self) -> comptime(T))Compile-time unwrap — panics at compile-time if None.
Returns: comptime(T)
comptime_unwrap_or : (fn(comptime(self) : Self, comptime(or_value) : T) -> comptime(T))Returns: comptime(T)
comptime_is_some : (fn(comptime(self) : Self) -> comptime(bool))Returns: comptime(bool)
comptime_is_none : (fn(comptime(self) : Self) -> comptime(bool))Returns: comptime(bool)
impl(generic(T : Type, E : Type), Option(Result(T, E)), ...)
impl(generic(T : Type), Option(T), ...)
ok_or : (fn(generic(E : Type), self : Self, err : E) -> Result(T, E))Convert Some(value) to Ok(value), or return Err(err) if None.
Returns: Result(T, E)
ok_or_else : (fn(generic(E : Type), self : Self, err_fn : Impl(Fn() -> E)) -> Result(T, E))Convert Some(value) to Ok(value), or call err_fn to produce Err if None.
Returns: Result(T, E)
impl(generic(T : Type), where(T <: Clone), Option(T), Clone(...))
impl(generic(T : Type), where(T <: Copy), Option(T), Copy())
impl(generic(T : Type), where(T <: Eq(T)), Option(T), Eq(Option(T)))
impl(generic(T : Type), where(T <: Ord(T)), Option(T), Ord(Option(T)))
impl(generic(T : Type), where(T <: Hash), Option(T), Hash(...))
hash : (fn(generic(H : Type), inout(self) : Self, inout(hasher) : H, where(H <: Hasher)) -> unit)DeriveContext — context passed to derive rule functions (needs Option).
Used by the derive macro to generate trait implementations.
Fields
| Name | Type | Description |
|---|---|---|
target | Expr | The AST expression for the target type. |
forall_params | Option(Expr) | Optional generic parameters for generic types. |
where_clause | Option(Expr) | Optional where clause for constrained generics. |
Trait Implementations
impl(DeriveContext, Comptime())
impl(DeriveContext, ...)
make_impl : (DeriveContext) fn(self : DeriveContext, trait_body : Expr) -> ExprResult — a value that is either success (Ok) or failure (Err).
Result(OkType, ErrorType) has two variants:
.Ok(value)— contains a success value of typeOkType.Err(error)— contains an error value of typeErrorType
Example
(r : Result(i32, str)) = .Ok(i32(42));
assert(r.is_ok(), "expected Ok");
Type Parameters
| Name | Type | Notes |
|---|---|---|
OkType | Type | comptime |
ErrorType | Type | comptime |
Trait Implementations
impl(generic(OkType : Type, ErrorType : Type), Result(OkType, ErrorType), ...)
unwrap : (fn(self : Self) -> OkType)Extract the Ok value, panicking if Err.
Returns: OkType
unwrap_err : (fn(self : Self) -> ErrorType)Extract the Err value, panicking if Ok.
Returns: ErrorType
is_ok : (fn(self : Self) -> bool)Return true if the result is Ok.
Returns: bool
is_err : (fn(self : Self) -> bool)Return true if the result is Err.
Returns: bool
impl(generic(OkType : Type, ErrorType : Type), Result(OkType, ErrorType), ...)
map : (fn(generic(B : Type), self : Self, f : Impl(Fn(a : OkType) -> B)) -> Result(B, ErrorType))Map the Ok value with f, leaving Err untouched.
Returns: Result(B, ErrorType)
map_err : (fn(generic(F : Type), self : Self, f : Impl(Fn(a : ErrorType) -> F)) -> Result(OkType, F))Map the Err value with f, leaving Ok untouched.
Returns: Result(OkType, F)
and_then : (fn(generic(B : Type), self : Self, f : Impl(Fn(a : OkType) -> Result(B, ErrorType))) -> Result(B, ErrorType))Chain a computation that may fail on the Ok value.
Returns: Result(B, ErrorType)
or_else : (fn(generic(F : Type), self : Self, f : Impl(Fn(a : ErrorType) -> Result(OkType, F))) -> Result(OkType, F))Chain a recovery computation on the Err value.
Returns: Result(OkType, F)
and : (fn(generic(B : Type), self : Self, res : Result(B, ErrorType)) -> Result(B, ErrorType))Return res if Ok, otherwise propagate Err.
Returns: Result(B, ErrorType)
or : (fn(generic(F : Type), self : Self, res : Result(OkType, F)) -> Result(OkType, F))Return self if Ok, otherwise return res.
Returns: Result(OkType, F)
ok : (fn(self : Self) -> Option(OkType))Convert to Option(OkType), discarding the error.
Returns: Option(OkType)
err : (fn(self : Self) -> Option(ErrorType))Convert to Option(ErrorType), discarding the success value.
Returns: Option(ErrorType)
map_or : (fn(generic(B : Type), self : Self, default_val : B, f : Impl(Fn(a : OkType) -> B)) -> B)Apply f if Ok, otherwise return default_val.
Returns: B
map_or_else : (fn(generic(B : Type), self : Self, default_fn : Impl(Fn(a : ErrorType) -> B), f : Impl(Fn(a : OkType) -> B)) -> B)Apply f if Ok, otherwise call default_fn with the error.
Returns: B
unwrap_or_else : (fn(self : Self, f : Impl(Fn(a : ErrorType) -> OkType)) -> OkType)Extract the Ok value, or call f with the error to produce a fallback.
Returns: OkType
unwrap_or : (fn(self : Self, or_value : OkType) -> OkType)Extract the Ok value, or return or_value if Err.
Returns: OkType
expect : (fn(self : Self, msg : str) -> OkType)Extract the Ok value, panicking with msg if Err.
Returns: OkType
expect_err : (fn(self : Self, msg : str) -> ErrorType)Extract the Err value, panicking with msg if Ok.
Returns: ErrorType
inspect : (fn(self : Self, f : Impl(Fn(a : OkType) -> unit)) -> Result(OkType, ErrorType))Call f with the Ok value (if any), then return the result.
Returns: Result(OkType, ErrorType)
inspect_err : (fn(self : Self, f : Impl(Fn(a : ErrorType) -> unit)) -> Result(OkType, ErrorType))Call f with the Err value (if any), then return the result.
Returns: Result(OkType, ErrorType)
impl(generic(OkType : Type, ErrorType : Type), where(OkType <: Default), Result(OkType, ErrorType), ...)
unwrap_or_default : (fn(self : Self) -> OkType)Extract the contained value, or T's default when None.
Returns: OkType
impl(generic(T : Type, E : Type), Result(Result(T, E), E), ...)
flatten : (fn(self : Self) -> Result(T, E))Collapse one level of nesting.
Returns: Result(T, E)
impl(generic(T : Type, E : Type), Result(Option(T), E), ...)
impl(generic(OkType : Type, ErrorType : Type), where(OkType <: Comptime, ErrorType <: Comptime), Result(OkType, ErrorType), Comptime())
impl(generic(OkType : Type, ErrorType : Type), where(OkType <: Comptime, ErrorType <: Comptime), Result(OkType, ErrorType), ...)
comptime_unwrap : (fn(comptime(self) : Self) -> comptime(OkType))Compile-time unwrap — panics at compile-time if Err.
Returns: comptime(OkType)
comptime_unwrap_err : (fn(comptime(self) : Self) -> comptime(ErrorType))Returns: comptime(ErrorType)
comptime_is_ok : (fn(comptime(self) : Self) -> comptime(bool))Returns: comptime(bool)
comptime_is_err : (fn(comptime(self) : Self) -> comptime(bool))Returns: comptime(bool)
impl(generic(T : Type, E : Type), where(T <: Clone, E <: Clone), Result(T, E), Clone(...))
impl(generic(T : Type, E : Type), where(T <: Copy, E <: Copy), Result(T, E), Copy())
impl(generic(T : Type, E : Type), where(T <: Eq(T), E <: Eq(E)), Result(T, E), Eq(Result(T, E)))
impl(generic(T : Type, E : Type), where(T <: Ord(T), E <: Ord(E)), Result(T, E), Ord(Result(T, E)))
impl(generic(T : Type, E : Type), where(T <: Hash, E <: Hash), Result(T, E), Hash(...))
hash : (fn(generic(H : Type), inout(self) : Self, inout(hasher) : H, where(H <: Hasher)) -> unit)Box(V): the old spelling of the shared, reference-counted cell, now Rc(V)
(plans/VALUES_BY_DEFAULT.md §6 V1 step 1). Nothing in std, src or tests
spells it. It stays defined for ONE seed only: the v0.2.54 seed compiles
src/ against this std and still synthesizes box(...) when dyn(...)
auto-boxes a payload that is not an object. Generation B part 2 deletes
Box/box once SEED_VERSION carries Rc as the canonical cell, and V1
step 2 later reintroduces Box as the unique, uncounted cell.
Type Parameters
| Name | Type | Notes |
|---|---|---|
V | Type | comptime |
Trait Implementations
impl(generic(T : Type), Box(T), Isolation(...))
can_isolate : (self -> (ref_count(self) == 1))impl(generic(T : Type), where(T <: Hash), Box(T), Hash(...))
hash : (fn(generic(H : Type), inout(self) : Self, inout(hasher) : H, where(H <: Hasher)) -> unit)impl(generic(T : Type), where(T <: Eq(T)), Box(T), Eq(Box(T)))
impl(generic(T : Type), where(T <: Clone), Box(T), Clone(...))
clone : (self -> box(self.*.clone()))impl(generic(T : Type), where(T <: Default), Box(T), Default(...))
default : (fn() -> Self)The default value of the type.
Returns: Self
impl(generic(T : Type), Box(T), Deref(...))
Target : TRc — a heap-allocated, reference-counted cell for a single value: the
shared, counted cell's name under plans/VALUES_BY_DEFAULT.md (§3.2,
decision 1). Copying a handle shares one heap value and bumps its count,
as with Rust's Rc<T>; w.* names the payload, and w.field /
w.method() reach it through auto-dereference (Deref).
Rc(V) is the canonical shared cell (V1 step 1, Generation B): the cell
the compiler synthesizes (dyn(v) auto-boxes into rc(v)), and the one
every std, src and test site spells. The legacy Box(V) above is a
separate type with the same definition, kept for the seed only.
a := rc(i32(42));
b := a; // a second handle to the same value
consume(b.* = i32(7));
assert(a.* == i32(7), "a and b name the same value");
Type Parameters
| Name | Type | Notes |
|---|---|---|
V | Type | comptime |
Trait Implementations
impl(generic(T : Type), Rc(T), Isolation(...))
can_isolate : (self -> (ref_count(self) == 1))impl(generic(T : Type), where(T <: Hash), Rc(T), Hash(...))
hash : (fn(generic(H : Type), inout(self) : Self, inout(hasher) : H, where(H <: Hasher)) -> unit)impl(generic(T : Type), where(T <: Eq(T)), Rc(T), Eq(Rc(T)))
impl(generic(T : Type), where(T <: Clone), Rc(T), Clone(...))
clone : (self -> rc(self.*.clone()))impl(generic(T : Type), where(T <: Default), Rc(T), Default(...))
default : (fn() -> Self)The default value of the type.
Returns: Self
impl(generic(T : Type), Rc(T), Deref(...))
Target : T=== Arc === Arc — an atomically reference-counted, thread-safe container for a single value.
Use arc(value) to allocate. Access the inner value with a.*.
Example
a := arc(i32(42));
assert(a.* == i32(42), "inner value is 42");
Type Parameters
| Name | Type | Notes |
|---|---|---|
V | Type | comptime |
Trait Implementations
impl(generic(T : Type), where(T <: (Send, Sync, Acyclic)), Arc(T), Send())
impl(generic(T : Type), where(T <: (Send, Sync, Acyclic)), Arc(T), Sync())
impl(generic(T : Type), where(T <: (Send, Sync, Acyclic)), Arc(T), Deref(...))
Target : TMaybeUninit — a wrapper that allows holding an uninitialized value.
Useful for FFI or low-level patterns where a value must be
allocated first and initialized later (e.g., by a C function).
assume_init takes the as_ptr() result as a witness — a pointer only
unsafe-capable code can hold — so safe code cannot read the uninitialized
slot (issues/fixed/safe-code-reads-uninitialized-memory-through-maybeuninit-assume-init.md).
Example
extern(
"C",
time_t : Type,
time : (fn(timer : ?*time_t) -> time_t)
);
uninitialized_timer := MaybeUninit(time_t).new();
ptr := uninitialized_timer.as_ptr();
time(.Some(ptr));
timer := uninitialized_timer.assume_init(ptr);
Type Parameters
| Name | Type | Notes |
|---|---|---|
BaseType | Type | comptime |
impl(generic(BaseType : Type), MaybeUninit(BaseType), ...)
new : (fn() -> Self)Create a new uninitialized value.
Returns: Self
as_ptr : (fn(inout(self) : Self) -> *BaseType)Get a mutable pointer to the underlying value.
Returns: *BaseType
assume_init : (fn(own(self) : Self, written : *BaseType) -> BaseType)Assume the value is initialized and extract it. Undefined behavior if
not initialized. The written witness is the as_ptr() result you
initialized through: a raw pointer only unsafe-capable code can hold, so
safe code cannot reach the uninitialized read. It is not inspected.
Returns: BaseType
_probe : (fn(self : Self) -> i32)Test-support probe for the member-visibility rule (E0405): a _-prefixed
method declared in the PRELUDE is private to this module exactly like one
declared in any other module
(issues/fixed/prelude-methods-have-no-visibility-owner.md). It has no
caller inside std/ — it exists so tests/member_visibility.test.yo can
assert from a foreign directory that the compiler rejects the call.
Returns: i32
Lazy iterator that maps each element through a function F.
Created by calling .map(f) on any iterator.
I is the source iterator type, B is the output element type,
F is the mapper closure type satisfying Fn(item : A) -> B.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
B | Type | comptime |
F | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type, B : Type, F : Type), where(I <: Iterator(Item := A), F <: (Fn(item : A) -> B)), IterMap(I, B, F), Iterator(...))
Item : Bnext : (fn(inout(self) : Self) -> Option(B))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(B)
Lazy iterator that skips elements for which the predicate returns false.
Created by calling .filter(pred) on any iterator.
I is the source iterator type, F is the predicate closure type
satisfying Fn(item : A) -> bool — by value, symmetric with map
(plans/archive/STD_API_AUDIT.md D3.4's callback-asymmetry fix).
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
F | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type, F : Type), where(I <: Iterator(Item := A), F <: (Fn(item : A) -> bool)), IterFilter(I, F), Iterator(...))
Item : Anext : (fn(inout(self) : Self) -> Option(A))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(A)
Lazy iterator that yields at most n elements from the source.
Created by calling .take(n) on any iterator.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type), where(I <: Iterator(Item := A)), IterTake(I), Iterator(...))
Item : Anext : (fn(inout(self) : Self) -> Option(A))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(A)
Lazy iterator that skips the first n elements of the source, then yields
all remaining elements.
Created by calling .skip(n) on any iterator.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type), where(I <: Iterator(Item := A)), IterSkip(I), Iterator(...))
Item : Anext : (fn(inout(self) : Self) -> Option(A))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(A)
Lazy iterator that pairs each element with its zero-based index.
Created by calling .enumerate() on any iterator.
Yields IterPair(usize, A) values where _0 is the index and _1 is
the original element.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
Trait Implementations
Lazy iterator that combines two iterators element-by-element into pairs. Stops as soon as either iterator is exhausted.
Created by calling .zip(other) on any iterator.
Yields IterPair(A, B) values.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
J | Type | comptime |
Trait Implementations
impl(generic(I : Type, J : Type, A : Type, B : Type), where(I <: Iterator(Item := A), J <: Iterator(Item := B)), IterZip(I, J), Iterator(...))
Item : IterPair(A, B)Lazy iterator that yields all of the first iterator, then all of the second.
Created by calling .chain(other) on any iterator. Both iterators must
yield the same Item type.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
J | Type | comptime |
Trait Implementations
impl(generic(I : Type, J : Type, A : Type), where(I <: Iterator(Item := A), J <: Iterator(Item := A)), IterChain(I, J), Iterator(...))
Item : Anext : (fn(inout(self) : Self) -> Option(A))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(A)
Lazy iterator that yields elements while pred holds, then stops forever.
Created by calling .take_while(pred) on any iterator.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
F | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type, F : Type), where(I <: Iterator(Item := A), F <: (Fn(item : A) -> bool)), IterTakeWhile(I, F), Iterator(...))
Item : Anext : (fn(inout(self) : Self) -> Option(A))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(A)
Lazy iterator that skips elements while pred holds, then yields the rest.
Created by calling .skip_while(pred) on any iterator.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
F | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type, F : Type), where(I <: Iterator(Item := A), F <: (Fn(item : A) -> bool)), IterSkipWhile(I, F), Iterator(...))
Item : Anext : (fn(inout(self) : Self) -> Option(A))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(A)
Lazy iterator that maps each element to an Option and yields the Somes.
Created by calling .filter_map(f) on any iterator. B is the output
element type, F satisfies Fn(item : A) -> Option(B).
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
B | Type | comptime |
F | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type, B : Type, F : Type), where(I <: Iterator(Item := A), F <: (Fn(item : A) -> Option(B))), IterFilterMap(I, B, F), Iterator(...))
Item : Bnext : (fn(inout(self) : Self) -> Option(B))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(B)
Iterator wrapper that can look at the next element without consuming it.
Created by calling .peekable() on any iterator. A is the element type.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
A | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type), where(I <: Iterator(Item := A)), IterPeekable(I, A), ...)
peek : (fn(inout(self) : Self) -> Option(A))Return the next element without consuming it. Repeated calls return
the same element until next() is called.
Returns: Option(A)
impl(generic(I : Type, A : Type), where(I <: Iterator(Item := A)), IterPeekable(I, A), Iterator(...))
Item : Anext : (fn(inout(self) : Self) -> Option(A))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(A)
Lazy iterator that yields the source's elements back-to-front.
Created by calling .rev() on any DoubleEndedIterator. next pulls from
the source's BACK and next_back from its FRONT, so .rev().rev() restores
the original order.
Type Parameters
| Name | Type | Notes |
|---|---|---|
I | Type | comptime |
Trait Implementations
impl(generic(I : Type, A : Type), where(I <: DoubleEndedIterator(Item := A)), IterRev(I), Iterator(...))
Item : Anext : (fn(inout(self) : Self) -> Option(A))Advance the iterator and return the next value, or None when exhausted.
Returns: Option(A)
impl(generic(I : Type, A : Type), where(I <: Iterator(Item := A)), IterRev(I), DoubleEndedIterator(...))
Item : Anext_back : (fn(inout(self) : Self) -> Option(A))Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Returns: Option(A)
FutureState — the state of an async Future.
Variants
| Variant | Fields | Description |
|---|---|---|
Cold | The future is cold: created but not yet started (an | |
Running | The future has started and is not finished: suspended at an await, or an I/O operation in flight. | |
Completed | The future completed successfully. | |
Aborted | The future was aborted (e.g., via |
Trait Implementations
impl(FutureState, Acyclic())
impl(FutureState, Runtime())
impl(FutureState, Send())
impl(FutureState, Sync())
impl(FutureState, Eq(FutureState))
Methods
clone : (FutureState) fn(inout(self) : FutureState) -> FutureState== : (FutureState) fn(lhs : FutureState, rhs : FutureState) -> bool!= : (FutureState) fn(lhs : FutureState, rhs : FutureState) -> boolJoinHandle — a handle to a spawned async task.
Generic over T, the return type of the spawned task.
The handle OWNS a reference to the task's future: the task (and its
result) stay alive for as long as some copy of the handle does, and
dropping the last copy releases it. A handle that is dropped without being
awaited DETACHES the task — it keeps running and frees itself when it
finishes — which is what makes a fire-and-forget io.spawn(…) statement
correct (it used to leak the whole state machine,
issues/fixed/statement-level-io-spawn-leaks-the-state-machine.md). Awaiting
does not consume the handle; awaiting it twice reads the same result.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(generic(T : Type), JoinHandle(T), ...)
await : __yo_join_handle_awaitAwait a Future, suspending until its result is ready.
Returns: unknown
impl(generic(T : Type), JoinHandle(T), Dispose(...))
dispose : (fn(self : Self) -> unit)Release the resources self owns — a file descriptor, a socket, a lock,
a buffer the allocator handed out. Called automatically when the value's
owner drops it (a value type) or the last reference to it goes away (a
reference type), so an implementor never calls it directly and must
tolerate being the only one who ever does.
It must be safe to run exactly once, and a type that also exposes an
explicit close/release is responsible for making the second call a
no-op.
Returns: unit
impl(generic(T : Type), JoinHandle(T), ...)
state : (fn(self : JoinHandle(T)) -> FutureState)The task's current FutureState, read without blocking or driving the
event loop (unlike await, which polls the loop to completion).
Returns: FutureState
as_ptr : (fn(self : JoinHandle(T)) -> *void)The task's future as an untyped pointer, for the runtime externs that
take a task (std/async's join waits, __yo_join_wait_add). The
handle keeps owning its reference; the pointer is valid while some copy
of the handle is alive. Reading through it is unsafe.
Returns: *void
is_finished : (fn(self : JoinHandle(T)) -> bool)True once the task is terminal — Completed or Aborted.
Returns: bool
abort : (fn(self : JoinHandle(T)) -> unit)Cancel the task: a non-terminal task is marked Aborted and will not
resume past its current suspension point (its pending completion, if
any, releases the state machine instead of resuming it). Completed and
already-aborted tasks are left untouched. await on an aborted handle
returns .None. An operation the task is suspended in is cancelled too
where the I/O backend can take the registration back (timers and park
futures on every backend; on Linux also the epoll and io_uring
descriptor and datagram operations, on macOS the kqueue-parked
descriptor operations): the task and what it was waiting on are then
released at once instead of when that operation would have completed.
An operation with no cancel path still runs to completion and releases
the task then; the task stays Aborted. A child future the task is
awaiting is aborted with it when the task started it (an anonymous
io.await(child(io), io), or a named future this await cold-started); a
named future someone else started may be shared and keeps running. A raw
IoFuture spawned directly is cancelled the same way.
Returns: unit
Io module — the async runtime effect.
Provides io.async, io.await, io.spawn, and io.state operations.
Automatically injected into main when declared with io : Io.
Fields
| Name | Type | Description |
|---|---|---|
async | fn(generic(T, E) action : Impl(Fn(E) -> T)) -> Impl(Future(T, E)) | Create a new |
await | fn(generic(T, E) fut : Impl(Future(T, E)), e : E) -> T | Await a |
state | fn(generic(T, E) fut : Impl(Future(T, E))) -> FutureState | The task's current |
spawn | fn(generic(T, E) fut : Impl(Future(T, E)), e : E) -> JoinHandle(T) | Spawn a |
Traits / Modules
Comptime trait — indicates a type that can be used at compile-time.
Examples: i32, bool, Type, comptime_int, comptime_float, comptime_str.
Non-examples: int, ushort (runtime-only types).
Implementors
Runtime trait — indicates a type that can be used at runtime.
Examples: i32, bool, *(i32), void.
Non-examples: comptime_int, comptime_float, comptime_str, Type (compile-time-only types).
Implementors
Send trait — a value of this type may be MOVED to another thread.
The compiler derives it (plans/VALUES_BY_DEFAULT.md §3.8): a value is
Send iff it reaches no non-atomic reference cell (Rc, Box, a
ref(struct(...))), every component is Send, and it holds no raw
pointer and no borrow. An atomic object is Send iff it is Sync, because
its copies share one payload. Raw pointers are neither Send nor Sync
unless a type opts in, with impl(T, Send()) under
pragma(Pragma.AllowUnsafe).
Implementors
Sync trait — copies of a value of this type may be READ from several threads at once.
Derived like Send, over shared reads instead of a move: plain data,
atomic cells (Arc, Atomic*, Mutex) and values composed of them are
Sync; a non-atomic reference cell is not, and neither is a raw pointer
unless a type opts in with impl(T, Sync()) under
pragma(Pragma.AllowUnsafe). A closure is Sync iff its captured state
is. Dyn(Trait) is Sync only as Dyn(Trait, Sync).
Implementors
Acyclic trait - indicates a type that cannot form reference cycles. Types that implement Acyclic don't need cycle collection tracking. Primitive types, value types without object fields, and objects that don't reference back to themselves (directly or indirectly) are Acyclic.
Implementors
MoveOnly trait - a value that cannot be copied, only moved.
A value type is move-only when it implements Dispose, when it declares
impl(T, MoveOnly()), or when one of its fields, variant payloads, tuple
or array elements, or closure captures is move-only. The compiler derives
it; a declaration is needed only for a type that has no Dispose but must
still never be duplicated (a token, a unique id).
A copy of a move-only value is a compile error (E0901). y := x moves
x, and so do passing it to an own(...) parameter, storing it in a
field or element, returning it and capturing it in a closure. A by-value
parameter borrows it, so use_file(f) needs no move. Only a value type
(struct, enum, newtype, and the tuples, arrays and closures built
from them) can be move-only. A reference type (ref(struct(...)), Rc,
Arc) is how a value is shared: its copies alias one cell, so it is never
move-only, even around a move-only payload.
Dropping the last copy of the handle releases the task's future.
Methods
dispose : fn(self : Self) -> unitRelease the resources self owns — a file descriptor, a socket, a lock,
a buffer the allocator handed out. Called automatically when the value's
owner drops it (a value type) or the last reference to it goes away (a
reference type), so an implementor never calls it directly and must
tolerate being the only one who ever does.
It must be safe to run exactly once, and a type that also exposes an
explicit close/release is responsible for making the second call a
no-op.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self |
Returns: unit
Implementors
Trace trait — mandatory for every reference type that can transitively hold a
managed reference. Auto-derived by the compiler for structs/enums (incl.
Option and all value types); hand-implemented for containers whose elements
live in a heap buffer (ArrayList, HashMap, …). The constructor wires
header.traverse_fn to this trace.
Like Dispose, only a reference type may implement it (checked at the
impl).
Methods
trace : fn(self : Self, tracer : GcTracer) -> unitImplementors
Index trait — enables container(idx) subscript syntax at runtime.
The Idx parameter is the index type (e.g., usize, Range(usize)).
Implementations must define an Output associated type and an index method.
Type Parameters
| Name | Type | Notes |
|---|---|---|
Idx | Type | comptime |
Implementors
IndexUnchecked — the bounds-check-free twin of Index(usize).
Codegen calls index_unchecked instead of index ONLY at a subscript the
verifier proved in bounds, in a verify-mode file
(plans/backlog/SAFE_MODE_5B_CONTAINER_BOUNDS_ELISION.md). It returns a raw
pointer, so safe code cannot call it. An impl's body must be its index
body minus the length test: anything weaker turns a proof into undefined
behavior.
Associated Types
| Name | Constraint | Description |
|---|---|---|
Output | Type | The output type of the addition. |
Methods
index_unchecked : fn(inout(self) : Self, idx : usize) -> *(Output)Implementors
ComptimeIndex — compile-time indexing trait for constant expressions.
Type Parameters
| Name | Type | Notes |
|---|---|---|
Idx | Type | comptime |
Implementors
Methods
..= : fn(start : Self : (Comptime), end : Self) -> RangeInclusive(Self : (Comptime))Parameters
| Name | Type | Notes |
|---|---|---|
start | Self : (Comptime) | comptime |
end | Self : (Comptime) | comptime |
Returns: RangeInclusive(Self : (Comptime))
Implementors
Negate trait — enables unary -value operator.
Associated Types
| Name | Constraint | Description |
|---|---|---|
Output | Type | The output type of the addition. |
Methods
neg : fn(self : Self) -> OutputImplementors
Associated Types
| Name | Constraint | Description |
|---|---|---|
Output | Type | The output type of the addition. |
Methods
neg : fn(self : Self : (Comptime)) -> Output : (Comptime)Implementors
BitNot trait — enables ~value bitwise complement.
Associated Types
| Name | Constraint | Description |
|---|---|---|
Output | Type | The output type of the addition. |
Methods
~ : fn(self : Self) -> OutputImplementors
Associated Types
| Name | Constraint | Description |
|---|---|---|
Output | Type | The output type of the addition. |
Methods
~ : fn(self : Self : (Comptime)) -> Output : (Comptime)Implementors
Eq trait — enables == and != comparison operators.
The != method has a default implementation that negates ==.
Type Parameters
| Name | Type | Notes |
|---|---|---|
Rhs | Type | comptime |
Implementors
Ord trait — enables <, <=, >, >= comparison operators.
Requires the type to also implement Eq.
cmp is contractually a TOTAL order for every std impl (the audit's
no-PartialOrd decision, plans/archive/STD_API_AUDIT.md D3.3): the default is
derived from </==, and types whose operators are only partial
(floats: NaN is incomparable under IEEE <) OVERRIDE cmp with a
total order instead of splitting the trait.
Type Parameters
| Name | Type | Notes |
|---|---|---|
Rhs | Type | comptime |
Implementors
Hasher — turns a stream of bytes into a u64 (Rust's std::hash::Hasher).
A Hash impl feeds a value's identity bytes to a hasher through the
write* methods; finish reads the hash of everything written so far
(it does not reset the hasher). write and finish are required; the
fixed-width write_* methods default to the value's native-endian bytes,
and an algorithm with a fast word path overrides them (std/hash's
SipHasher13 overrides write_u64).
Implementations live in std/hash: SipHasher13 (keyed, the HashMap
default), Fnv1aHasher, and the hash_one helper.
Methods
write : fn(inout(self) : Self, buf : *(u8), size : usize) -> unitFeed size bytes starting at buf.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
buf | *(u8) | |
size | usize |
Returns: unit
finish : fn(inout(self) : Self) -> u64The hash of everything written so far.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self |
Returns: u64
write_u8 : fn(inout(self) : Self, v : u8) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | u8 |
Returns: unit
write_u16 : fn(inout(self) : Self, v : u16) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | u16 |
Returns: unit
write_u32 : fn(inout(self) : Self, v : u32) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | u32 |
Returns: unit
write_u64 : fn(inout(self) : Self, v : u64) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | u64 |
Returns: unit
write_usize : fn(inout(self) : Self, v : usize) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | usize |
Returns: unit
write_i8 : fn(inout(self) : Self, v : i8) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | i8 |
Returns: unit
write_i16 : fn(inout(self) : Self, v : i16) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | i16 |
Returns: unit
write_i32 : fn(inout(self) : Self, v : i32) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | i32 |
Returns: unit
write_i64 : fn(inout(self) : Self, v : i64) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | i64 |
Returns: unit
write_isize : fn(inout(self) : Self, v : isize) -> unitParameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
v | isize |
Returns: unit
Implementors
Hash trait - Similar to Rust's std:#️⃣:Hash
A type says which bytes make up its identity by feeding them to a
Hasher; the hasher (any Hasher, chosen by the caller) turns them into
a u64. Types that implement Hash can be used as keys in HashMap and
HashSet.
The contract, as in Rust:
- Consistent with Eq: if a == b, then a and b feed identical bytes.
- Prefix-free where it matters: variable-length data writes a length or
a terminator (String writes its bytes then 0xFF), so
("ab","c")and("a","bc")differ.
To hash a single value use std/hash's hash_one(value); to hash into a
hasher you already hold, call value.hash(hasher).
Methods
hash : fn(generic(H) inout(self) : Self, inout(hasher) : H : (Hasher)) -> unitFeed this value's identity into hasher.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
hasher | H : (Hasher) |
Returns: unit
Implementors
Clone trait — deep-copy a value.
Methods
clone : fn(inout(self) : Self) -> SelfCreate an independent clone of self.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self |
Returns: Self
Implementors
Copy trait - a value whose copy is a bitwise copy (plans/VALUES_BY_DEFAULT.md decision 36).
Copy requires Clone, as Rust's Copy: Clone: the where(Self <: Clone) below makes every Copy impl need a Clone impl that covers the
same instantiations, and makes where(T <: Copy) give T <: Clone in a
generic body. The compiler never writes the Clone impl. A named type
opts in with derive(T, Copy, Clone), and a generic one with
derive(generic(T : Type), where(T <: Clone), Pair(T), Clone) beside
impl(generic(T : Type), where(T <: Copy), Pair(T), Copy()) — the
derive's clone calls .clone() on its fields, so it needs the bound.
The impl is checked: every
field, variant payload and element must be Copy, and the type must not
implement Dispose (a copy would dispose twice) or declare MoveOnly.
A hand-written Clone is an error only on a type that is Copy for
every instantiation it serves: there clone() is the copy, so the
derived, field-wise clone is the only spelling.
The integers, floats, bool, char and the C number types, unit,
str views and raw pointers implement it here, each beside its Clone,
and Option(T) and Result(T, E) do when their payloads do. A tuple, an
Array(T, N), an anonymous record, a closure and a fn pointer have no
declaration to annotate, so each is Copy, and Clone, when all its
parts are. Box, Rc, Arc, String, the collections and Dyn never
are.
Today every value type without an owned buffer is still copied
implicitly, Copy or not. Generation B of decision 36 makes Copy the
rule: a named type without it is then moved at its last use, and a later
use is E0901.
Implementors
Default trait — the type's default value (Rust's Default).
Call explicitly via (T <: Default).default() in generic code, or
MyType.default() on a concrete type. Unblocks
Option.unwrap_or_default and map or_default-style helpers
(plans/archive/STD_API_AUDIT.md D3.1).
Methods
default : fn() -> SelfThe default value of the type.
Returns: Self
Implementors
ComptimeToString trait — compile-time string conversion.
Methods
to_comptime_string : fn(self : Self : (Comptime)) -> comptime_strRender this type for DISPLAY — diagnostics, comptime_assert messages, generated comments.
NOT a source renderer: the result is not guaranteed to reparse. An
instantiated generic has no written name to return, so it renders as a
placeholder (<struct:struct_yo_id_5916>, <enum:enum_yo_id_3586>).
Metaprogramming that needs to NAME a type in generated code must not use
this — construct through Self, or reach the type as a value via
Type.get_struct_fields(Self).get(i).field_type, which needs no name and
no import at the use site.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self : (Comptime) | comptime |
Returns: comptime_str
Implementors
Integer — marker for the ten built-in integer types, so the arithmetic
below can be written ONCE over T instead of ten times per method.
It exists because those bodies need T.MIN/T.MAX and ordering, which a
where(T <: Integer) impl resolves through the type parameter. f32/f64
are deliberately NOT members: float arithmetic saturates to infinity rather
than overflowing, so checked_* would be meaningless on them.
Implementors
Marks the SIGNED integers. abs and signum exist only for them — Rust
omits both on unsigned types, where abs would be the identity and
signum could only ever answer 0 or 1. A marker trait is how a blanket
impl gets restricted to half the integers, since where(T <: Integer)
covers all ten.
Implementors
The same-width UNSIGNED counterpart of a signed integer type.
An ASSOCIATED TYPE, which is the whole point: unsigned_abs needs to name
"the unsigned type of the same width" in its RESULT position, and
T.Unsigned is exactly that name. Without it the method would have to be
written out once per signed type — five copies of one body, differing only
in a cast.
Associated Types
| Name | Constraint | Description |
|---|---|---|
Unsigned | Type |
Implementors
The width in BYTES, as a TRAIT member so it can be read from a TYPE
position — -> Array(u8, T.BYTES). BITS is an inherent associated
constant and works in a VALUE position; an inherent constant does NOT
resolve as an Array length, so this one is declared through a trait
(issues/an-inherent-associated-constant-does-not-resolve-as-an-array-length.md).
Implementors
Marks the UNSIGNED integers — the mirror of SignedInteger, and what
restricts the power-of-two blanket below to the half of the integers Rust
defines it on. is_power_of_two on a signed type would have to answer for
negative receivers, and Rust simply does not offer it there.
Implementors
=== Deref ===
Deref — marks a wrapper whose members forward to its payload Target
(auto-dereference, plans/VALUES_BY_DEFAULT.md §3.3). Nothing is called at
run time: w.field and w.method() on a Deref type whose own members
lack that name mean w.*.field and w.*.method(), recursively through
nested wrappers. A name both have is E0616 (decision 32): Rc.clone(b)
is the Rc's clone, b.*.clone() the payload's. w.* is the payload.
Implemented by Box, Rc and Arc only; any other impl(..., Deref(...)) is
a compile error, so every auto-dereference goes through one of the
prelude's cells.
P :: struct(n : i32);
b := rc(P(n : i32(1)));
b.n = i32(2); // writes b.*.n
assert(b.n == i32(2), "read through the box");
Associated Types
| Name | Constraint | Description |
|---|---|---|
Target | Type | The payload type |
Implementors
Iterator trait — lazy, pull-based sequence traversal.
Associated Types
| Name | Constraint | Description |
|---|---|---|
Item | Type | The type of elements yielded — must equal |
Methods
next : fn(inout(self) : Self) -> Option(Item)Advance the iterator and return the next value, or None when exhausted.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self |
Returns: Option(Item)
Implementors
DoubleEndedIterator trait — an Iterator that can also be advanced from the
BACK. next and next_back consume from opposite ends of the same sequence
and meet in the middle; once they meet, both return .None.
Declares its own Item, which is how next_back's signature can name it.
It deliberately carries NO where-clause tying it to Iterator: a trait
cannot constrain another trait's associated type to its OWN
(where(Self <: Iterator(Item := Self.Item)) is rejected — the constraint
value must be a type, not an associated-type projection of Self).
COHERENCE RULE (not compiler-checked): an impl's DoubleEndedIterator.Item
MUST equal its Iterator.Item. The associated-type registry is keyed by
(type id, label) with no trait discrimination and takes the FIRST match, so a
mismatch is silently first-wins rather than diagnosed. Every impl in std
pairs the two traits on the same type with the same Item.
Associated Types
| Name | Constraint | Description |
|---|---|---|
Item | Type | The type of elements yielded — must equal |
Methods
next_back : fn(inout(self) : Self) -> Option(Item)Advance the iterator from the back and return the previous value, or
None when the two ends have met.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self |
Returns: Option(Item)
Implementors
FromIterator trait — build Self from a sequence of Self.Elem values.
The iteration loop lives in the blanket collect below, not here, so this
trait stays MONOMORPHIC: a seed constructor plus one element-at-a-time step,
both statics, dispatched the way sum calls (A <: Default).default().
That is what removes the need for a trait method carrying its own
generic(...) + where.
The element type is deliberately named Elem, NOT Item: the assoc-type
registry is keyed by (type id, label) with no trait discrimination, so an
Item here would collide with the collection's own IntoIterator.Item and
resolve first-wins by load order — benign for ArrayList, but genuinely
divergent for HashMap, whose IntoIterator.Item is MapEntry(K, V).
from_iter_add takes the accumulator by own and RETURNS it, so that one
signature covers reference collections (mutate acc, return it — the return
is a rebind of the same object) and value types such as String, whose
write into a borrowed parameter would land in a copy (E0908).
Associated Types
| Name | Constraint | Description |
|---|---|---|
Elem | Type | The element type this collection is built from. |
Methods
from_iter_new : fn() -> SelfThe empty collection collect starts from.
Returns: Self
from_iter_add : fn(sink(acc) : Self, item : Elem) -> SelfAdd one element to a partially-built collection and return it.
Parameters
| Name | Type | Notes |
|---|---|---|
acc | Self | |
item | Elem |
Returns: Self
Implementors
TryFrom trait — fallible conversion from one type to another.
From trait — infallible conversion FROM another type
(plans/archive/STD_API_AUDIT.md D3.2; the fallible pair is TryFrom below).
Type Parameters
| Name | Type | Notes |
|---|---|---|
Source | Type | comptime |
Implementors
Functions
Allocate a value in a fresh reference-counted cell: rc(value) takes
ownership of value and returns an Rc(V) whose ref_count is 1. rc is
an ordinary function, not the count: the count is the ref_count(x)
builtin (plans/VALUES_BY_DEFAULT.md decision 11).
a := rc(i32(42));
assert(ref_count(a) == usize(1), "a fresh cell has one owner");
b := a;
assert(b.* == i32(42), "a copy shares the cell");
Type Parameters
| Name | Type | Notes |
|---|---|---|
V | Type | comptime |
Parameters
| Name | Type | Notes |
|---|---|---|
value | V |
Returns: Rc(V)
for macro — iterate over a collection.
for(coll, x => body) — calls coll.into_iter() and binds x
to each yielded value. The collection is moved into the
iterator; object elements are handles, so mutating x in the
body mutates the element in place.
for(coll, inout(x) => body) — the borrowed form
(plans/archive/INOUT_LOCAL_BINDINGS_AUDIT.md §7): the collection is
pinned by a hidden local, its runtime borrow flag is held for the
whole loop, and each element is bound in place as an inout local
through the pointer iterator iter() (no per-element dup; struct
elements mutate in place). Any container operation that could
invalidate an element (growth, shrink, removal) — reached through ANY
handle — panics deterministically instead of leaving x dangling.
Maps take for(map, (k, inout(v)) => body): the key by value, only
the value borrowed, so a body can never rewrite a key in place.
Value-type collections (Array(T, N)) and combinator chains have no
iter(); use the value form.
Combinator chains (coll.into_iter().map(f), etc.) work
transparently: a blanket into_iter impl on Iterator (below)
makes every iterator its own IntoIterator.
Examples
// Object elements — mutate in place through the handle.
for(names, s => {
s.push_str("!");
});
// Consume an iterator chain.
for(list.into_iter(), x => print(x));
// Borrow struct elements in place (read AND write).
for(enemies, inout(e) => {
e.hp = (e.hp - i32(1));
});
Parameters
| Name | Type | Notes |
|---|---|---|
coll | Expr | |
handle | Expr |
Returns: unquote(Expr)
Examples
Constants
The unsafe module — provides low-level unwind hatches.
Value: source_namespace_9239973348331418852_0(drop: <fn(value)>, cast: <unknown: fn(generic(_Self) self : _Self, Target : Type) -> Target>)
Value: source_namespace_9239973348331418852_1(Call: (<fn(self)>, <fn(self)>))
Value: source_namespace_9239973348331418852_1(Call: (<fn(self)>, <fn(self)>))
Value: source_namespace_9239973348331418852_2(Call: (<fn(self)>, <fn(self)>))
Value: source_namespace_9239973348331418852_3(Call: (<fn(self)>, <fn(self)>))
Var — compile-time variable introspection utilities.
Provides macros for querying metadata about a variable at compile-time, such as ownership status and alias information.
Value: source_namespace_9239973348331418852_4(is_owning_the_rc_value: <fn(variable)>, has_other_aliases: <fn(variable)>)