Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

BoundMethod

Caches one authenticated reflected method and its checked access policy.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. 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.

BoundMethod

pub final class BoundMethod<R>

Caches one authenticated reflected method and its checked access policy.

The compiler creates this nonowning view only after validating a published MethodInfo and the requested result type. It does not retain the metadata generation or a receiver. A descriptor-changing reload requires restart; a compatible body replacement keeps the binding's method identity. Call and CallStatic check the complete invocation frame before performing reflected copies, moves, or writes. Ordinary values use delayed value transfer; explicit Argument records select reference and output modes. The caller keeps every receiver and argument source live through the call.

Example

module example.reflection_binding;
from std.reflection import TypeOf;

class Counter {
    pub init() {}
    pub readonly fn Current() -> i32 { return 42; }
}

pub fn Main() -> i32 {
    let Method = TypeOf<Counter>().MethodAt(.Declared, 0)!;
    let Instance = Counter();
    switch Method.Bind<i32>() {
        case .Ok { Value = Bound } => {
            if Method.Bind<bool>() is .Ok { Value = _ } { return 1; }
            switch Bound.Call(Instance) {
                case .Ok { Value = Answer } => return Answer;
                case .Err { Error = _ } => return 2;
            }
        }
        case .Err { Error = _ } => return 3;
    }
}

BoundMethod.Call

pub readonly fn Call<I, each A>(Instance: readonly I&, each Arguments: A&&) -> Result<R, InvocationStatus>

Calls this bound method on a readable live instance. I: Static instance type. A: Inferred argument types and categories. Instance: Live receiver. Arguments: Ordered delayed sources. Return: Owned result or checked failure.

BoundMethod.Call

pub readonly fn Call<I, each A>(Instance: mut I&, each Arguments: A&&) -> Result<R, InvocationStatus>

Calls this bound method on a writable live instance. I: Static instance type. A: Inferred argument types and categories. Instance: Live writable receiver. Arguments: Ordered delayed sources. Return: Owned result or checked failure.

BoundMethod.CallStatic

pub readonly fn CallStatic<each A>(each Arguments: A&&) -> Result<R, InvocationStatus>

Calls a bound static method. A: Inferred argument types and categories. Arguments: Ordered delayed sources. Return: Owned result or checked failure.

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