Values
Borrows one live value through its exact descriptor and access mode.
Module std.reflection
import std.reflection;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
ValueRef
pub final class ValueRefBorrows one live value through its exact descriptor and access mode.
ValueRef is opaque, Copyable, non-owning, and non-retaining. It never boxes, copies, moves, or extends the backing lifetime. Move, deinit, reallocation, or documented mutation may invalidate it.
ValueRef.Address
pub Address: void*;Returns borrowed untyped address. Return: Nonowning address.
ValueRef.Type
pub Type: TypeInfo;Returns exact semantic type. Return: Type descriptor.
ValueRef.Access
pub Access: AccessMode;Returns preserved read/write authority. Return: AccessMode.
ReadBorrow
pub final class ReadBorrow<T>Borrows a reflected value without copying or owning it.
The compiler authenticates construction and ties the address to its source object or published static generation. Copying this readonly view never extends that source's lifetime. See the reflection workflow for a complete checked field lookup and borrow example.
ReadBorrow.Get
pub readonly fn Get() -> readonly T&Borrows the checked value. Return: Readonly alias valid while the source remains live.
WriteBorrow
pub final class WriteBorrow<T>Borrows writable reflected storage without transferring ownership.
The compiler authenticates construction from a live writable source. This view cannot be copied, preventing a second writable alias through ordinary class copying. Moving the view does not move the referent.
WriteBorrow.init
pub init(Source: readonly Self&) = delete;WriteBorrow.operator
pub fn operator =(Source: readonly Self&) -> void = delete;WriteBorrow.Get
pub fn Get() -> mut T&Borrows writable storage. Return: Writable alias valid while the source remains live.
WriteBorrow.Get
pub readonly fn Get() -> readonly T&Borrows storage without write authority. Return: Readonly alias valid while the source remains live.
Output
pub final class Output<T>Owns one optional reflected out value in caller storage.
An empty Output contains no live T. A checked reflected call may initialize its inline storage through Out(Output); Reset and automatic deinit destroy a live value, while Take transfers it and leaves the Output empty. Output cannot be copied or moved because its inline address may be borrowed.
Example
module example.reflection_output;
from std.reflection import Output, Out;
pub fn Main() -> i32 {
var Slot = Output<i32>();
if Slot.HasValue() { return 1; }
if Slot.Borrow() is .Some { Value = _ } { return 2; }
if Slot.BorrowMut() is .Some { Value = _ } { return 3; }
switch Slot.Take() {
case .Ok { Value = _ } => return 4;
case .Err { Error = Failure } => {
if Failure != .OutputRequired { return 5; }
}
}
if Out(Slot).Mode != .Out { return 6; }
Slot.Reset();
if Slot.HasValue() { return 7; }
return 42;
}Output.init
pub init()Creates empty caller-owned out storage.
Output.init
pub init(Source: readonly Self&) = delete;Rejects copying caller-owned out storage.
Output.init
pub init(Source: mut Self&&) = delete;Rejects moving caller-owned out storage.
Output.operator
pub fn operator =(Source: readonly Self&) -> void = delete;Rejects copying assignment.
Output.operator
pub fn operator =(Source: mut Self&&) -> void = delete;Rejects moving assignment.
Output.HasValue
pub readonly fn HasValue() -> boolReports whether a reflected call initialized T. Return: True only while T is live.
Output.Borrow
pub readonly fn Borrow() -> ReadBorrow<T>?Borrows a live result without copying it. Return: Readonly borrow or none when empty.
Output.BorrowMut
pub fn BorrowMut() -> WriteBorrow<T>?Borrows a live result with write access. Return: Writable borrow or none when empty.
Output.Take
pub fn Take() -> Result<T, InvocationStatus> where T: MovableMoves out a live result and empties storage. Return: Value or OutputRequired.
Output.Reset
pub fn Reset() -> voidDestroys any live value and leaves storage empty.
Out
pub fn Out<T>(Value: mut Output<T>&) -> ArgumentRecords one checked out argument backed by caller-owned Output storage. T: Exact out type. Value: Empty output retained by the caller through the call. Return: Delayed nonowning Argument with no early initialization.
RefRead
pub fn RefRead<T>(Value: readonly T&) -> ArgumentRecords a delayed read-only reference argument from a live object.
The returned argument borrows Value through the checked call. The compiler validates its exact type and pass mode before invoking the method.
T: Exact source object type. Value: Readable source kept live through the reflected call. Return: Nonowning argument record with RefRead mode.
Example
module example.reflected_references;
from std.reflection import TypeOf, RefRead, RefWrite;
class Accumulator {
pub init() {}
pub readonly fn Add(Left: readonly i32&, Right: mut i32&) -> i32 {
Right += Left;
return Right;
}
}
pub fn Main() -> i32 {
let Method = TypeOf<Accumulator>().MethodAt(.Declared, 0)!;
let Instance = Accumulator();
let Left: i32 = 2;
var Right: i32 = 40;
switch Method.Bind<i32>() {
case .Ok { Value = Bound } => {
switch Bound.Call(Instance, RefRead(Left), RefWrite(Right)) {
case .Ok { Value = Answer } => {
if Right == 42 { return Answer; }
return 1;
}
case .Err { Error = _ } => return 2;
}
}
case .Err { Error = _ } => return 3;
}
}RefWrite
pub fn RefWrite<T>(Value: mut T&) -> ArgumentRecords a delayed writable reference argument from a live object. T: Exact source object type. Value: Writable source kept live through the reflected call. Return: Nonowning argument record with RefWrite mode.
ValueSlot
pub final class ValueSlotWraps caller-owned raw storage for one reflected result or output value.
ValueSlot is non-Copy and owns neither storage nor value cleanup. A Live slot must be destroyed or taken before its backing storage ends. Dropping the wrapper never destroys or frees the backing allocation.
ValueSlot.Address
pub Address: mut void*;Returns writable storage address. Return: Caller-owned base.
ValueSlot.Type
pub Type: TypeInfo;Returns exact admitted value type. Return: Type descriptor.
ValueSlot.Capacity
pub Capacity: usize;Returns writable byte capacity. Return: Storage extent.
ValueSlot.Alignment
pub Alignment: usize;Returns caller-promised alignment. Return: Nonzero power-of-two bytes.
ValueSlot.State
pub State: ValueSlotState;Returns current exact lifetime state. Return: Empty or Live.
Argument
pub final class ArgumentRecords one delayed nonowning invocation argument operation.
Factories do not perform copy, move, reference binding, or out initialization; checked validation completes before any frame effect.
Argument.Mode
pub Mode: ArgumentMode;Returns delayed operation kind. Return: ArgumentMode.
Argument.CopyValue
pub static fn CopyValue(Value: ValueRef) -> ArgumentRecords a future Copyable by-value copy. Value: Borrowed source. Return: Nonretaining argument.
Argument.MoveValue
pub static fn MoveValue(Value: ValueRef) -> ArgumentRecords a future checked move; Data sources remain unchanged. Value: Writable source view. Return: Nonretaining argument.
Argument.RefRead
pub static fn RefRead(Value: ValueRef) -> ArgumentRecords a future read reference. Value: Readable source view. Return: Nonretaining argument.
Argument.RefWrite
pub static fn RefWrite(Value: ValueRef) -> ArgumentRecords a future writable reference. Value: Writable source view. Return: Nonretaining argument.
Argument.RValue
pub static fn RValue(Value: ValueRef) -> ArgumentRecords direct rvalue-reference access. Value: Writable temporary/source view. Return: Nonretaining argument.
Argument.Out
pub static fn Out(Value: mut ValueSlot&) -> ArgumentRecords one caller-owned Empty output slot. Value: Writable slot borrow. Return: Nonretaining argument.
InvocationFrame
pub final class InvocationFrameBorrows one complete checked invocation frame.
The non-Copy frame borrows instance, argument slice, optional result slot, and private-access authority only through Invoke. It allocates and retains nothing. Validation failure leaves all supplied storage unchanged.
InvocationFrame.Instance
pub Instance: ValueRef?;Returns optional instance view. Return: None only for static calls.
InvocationFrame.Arguments
pub Arguments: readonly Argument[];Borrows ordered argument records. Return: Nonretaining read slice.
InvocationFrame.HasResult
pub HasResult: bool;Reports whether a result slot was supplied. Return: Slot-presence state.
InvocationFrame.Access
pub Access: PrivateAccess;Returns one-operation private access authority. Return: PrivateAccess.
InvocationFrame.WithoutResult
pub static fn WithoutResult(
Instance: ValueRef?,
Arguments: readonly Argument[],
Access: PrivateAccess
) -> InvocationFrameCreates a frame with no result storage. Instance: Optional exact receiver view. Arguments: Ordered records kept live through Invoke. Access: Explicit private operation authority. Return: Nonowning frame suitable only for a void callable.
InvocationFrame.WithResult
pub static fn WithResult(
Instance: ValueRef?,
Arguments: readonly Argument[],
Result: mut ValueSlot&,
Access: PrivateAccess
) -> InvocationFrameCreates a frame borrowing one Empty result slot. Instance: Optional exact receiver view. Arguments: Ordered records kept live through Invoke. Result: Empty caller-owned result storage kept live through Invoke. Access: Explicit private operation authority. Return: Nonowning frame suitable for one nonvoid callable.