Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Snapshot · Oct 24, 2026 · Frozen documentation

Values

Borrows one live value through its exact descriptor and access mode.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

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 ValueRef

Borrows 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.

pub Address: void*

pub Address: void*

Returns borrowed untyped address. Return: Nonowning address.

pub Type: TypeInfo

pub Type: TypeInfo

Returns exact semantic type. Return: Type descriptor.

pub Access: AccessMode

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.

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.

Get

pub fn Get() -> mut T&

Borrows writable storage. Return: Writable alias valid while the source remains live.

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;
}

pub init()

pub init()

Creates empty caller-owned out storage.

pub init(Source: readonly Self&) = delete;

pub init(Source: readonly Self&) = delete;

Rejects copying caller-owned out storage.

pub init(Source: mut Self&&) = delete;

pub init(Source: mut Self&&) = delete;

Rejects moving caller-owned out storage.

operator

pub fn operator =(Source: readonly Self&) -> void = delete;

Rejects copying assignment.

operator

pub fn operator =(Source: mut Self&&) -> void = delete;

Rejects moving assignment.

HasValue

pub readonly fn HasValue() -> bool

Reports whether a reflected call initialized T. Return: True only while T is live.

Borrow

pub readonly fn Borrow() -> ReadBorrow<T>?

Borrows a live result without copying it. Return: Readonly borrow or none when empty.

BorrowMut

pub fn BorrowMut() -> WriteBorrow<T>?

Borrows a live result with write access. Return: Writable borrow or none when empty.

Take

pub fn Take() -> Result<T, InvocationStatus> where T: Movable

Moves out a live result and empties storage. Return: Value or OutputRequired.

Reset

pub fn Reset() -> void

Destroys any live value and leaves storage empty.

Out

pub fn Out<T>(Value: mut Output<T>&) -> Argument

Records 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&) -> Argument

Records 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&) -> Argument

Records 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 ValueSlot

Wraps 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.

pub Address: mut void*

pub Address: mut void*

Returns writable storage address. Return: Caller-owned base.

pub Type: TypeInfo

pub Type: TypeInfo

Returns exact admitted value type. Return: Type descriptor.

pub Capacity: usize

pub Capacity: usize

Returns writable byte capacity. Return: Storage extent.

pub Alignment: usize

pub Alignment: usize

Returns caller-promised alignment. Return: Nonzero power-of-two bytes.

pub State: ValueSlotState

pub State: ValueSlotState

Returns current exact lifetime state. Return: Empty or Live.

Argument

pub final class Argument

Records one delayed nonowning invocation argument operation.

Factories do not perform copy, move, reference binding, or out initialization; checked validation completes before any frame effect.

pub Mode: ArgumentMode

pub Mode: ArgumentMode

Returns delayed operation kind. Return: ArgumentMode.

CopyValue

pub static fn CopyValue(Value: ValueRef) -> Argument

Records a future Copyable by-value copy. Value: Borrowed source. Return: Nonretaining argument.

MoveValue

pub static fn MoveValue(Value: ValueRef) -> Argument

Records a future checked move; Data sources remain unchanged. Value: Writable source view. Return: Nonretaining argument.

RefRead

pub static fn RefRead(Value: ValueRef) -> Argument

Records a future read reference. Value: Readable source view. Return: Nonretaining argument.

RefWrite

pub static fn RefWrite(Value: ValueRef) -> Argument

Records a future writable reference. Value: Writable source view. Return: Nonretaining argument.

RValue

pub static fn RValue(Value: ValueRef) -> Argument

Records direct rvalue-reference access. Value: Writable temporary/source view. Return: Nonretaining argument.

Out

pub static fn Out(Value: mut ValueSlot&) -> Argument

Records one caller-owned Empty output slot. Value: Writable slot borrow. Return: Nonretaining argument.

InvocationFrame

pub final class InvocationFrame

Borrows 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.

pub Instance: ValueRef?

pub Instance: ValueRef?

Returns optional instance view. Return: None only for static calls.

pub Arguments: readonly Argument[]

pub Arguments: readonly Argument[]

Borrows ordered argument records. Return: Nonretaining read slice.

pub HasResult: bool

pub HasResult: bool

Reports whether a result slot was supplied. Return: Slot-presence state.

pub Access: PrivateAccess

pub Access: PrivateAccess

Returns one-operation private access authority. Return: PrivateAccess.

WithoutResult

pub static fn WithoutResult(
        Instance: ValueRef?,
        Arguments: readonly Argument[],
        Access: PrivateAccess
    ) -> InvocationFrame

Creates 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.

WithResult

pub static fn WithResult(
        Instance: ValueRef?,
        Arguments: readonly Argument[],
        Result: mut ValueSlot&,
        Access: PrivateAccess
    ) -> InvocationFrame

Creates 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.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library