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

Views

Walks existing reflected member tables without copying or allocating them.

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.

FieldView

pub final class FieldView

Walks existing reflected member tables without copying or allocating them.

Each view stores a descriptor and query. Each cursor snapshots the selected count and advances independently. The descriptors borrow their published generation; retain neither view nor cursor beyond that generation.

Example

module example.reflection_views;
from std.reflection import TypeOf, MemberQuery;
attribute Marker {}
[Marker] pub struct Sample {
    [Marker] pub Value: i32;
    [Marker] pub Total: i32 { get; set; }
    [Marker] pub readonly fn Read([param: Marker] Amount: i32) -> i32 {
        return Value + Amount;
    }
}
fn Main() -> i32 {
    let Type = TypeOf<Sample>();
    if !Type.HasAttribute<Marker>() { return 4; }
    let Field = switch Type.FindField("Value") {
        case .Ok { Value = Found } => break Found;
        case .Err { Error = _ } => return 1;
    };
    let Property = switch Type.FindProperty("Total") {
        case .Ok { Value = Found } => break Found;
        case .Err { Error = _ } => return 2;
    };
    if Field.Name != "Value" || Property.Name != "Total" ||
        !Field.HasAttribute<Marker>() || !Property.HasAttribute<Marker>() {
        return 3;
    }
    var Count = 0;
    for TypeAttribute in Type.Attributes() { Count += 1; }
    for TypeEffective in Type.EffectiveAttributes() { Count += 1; }
    for TypeSelected in Type.AttributesOf<Marker>() { Count += 1; }
    for EffectiveSelected in Type.EffectiveAttributesOf<Marker>() { Count += 1; }
    if !Type.HasEffectiveAttribute<Marker>() { return 5; }
    if Type.AttributeSite() is .Some { Value = Site } {
        if !Site.HasAttribute<Marker>() || !Site.HasEffectiveAttribute<Marker>() { return 6; }
        for SiteDirect in Site.Attributes() { Count += 1; }
        for SiteEffective in Site.EffectiveAttributes() { Count += 1; }
    }
    for FieldAttribute in Field.Attributes() { Count += 1; }
    for FieldEffective in Field.EffectiveAttributes() { Count += 1; }
    for PropertyAttribute in Property.Attributes() { Count += 1; }
    for PropertyEffective in Property.EffectiveAttributes() { Count += 1; }
    for IteratedField in Type.Fields() { Count += 1; }
    for IteratedProperty in Type.Properties(MemberQuery.Declared) { Count += 1; }
    for Method in Type.Methods() {
        for MethodAttribute in Method.Attributes() { Count += 1; }
        for MethodEffective in Method.EffectiveAttributes() { Count += 1; }
        if Method.HasAttribute<Marker>() {
            if Method.ParameterAt(0) is .Some { Value = Parameter } {
                for ParameterAttribute in Parameter.Attributes() { Count += 1; }
                for ParameterEffective in Parameter.EffectiveAttributes() { Count += 1; }
                if Parameter.HasAttribute<Marker>() { Count += 1; }
            }
        }
    }
    return Count;
}

FieldView.CreateIterator

pub readonly fn CreateIterator() -> FieldIterator

Starts independent field traversal. Return: Allocation-free cursor.

FieldIterator

pub final class FieldIterator

Owns one field-table cursor.

FieldIterator.Next

pub fn Next() -> FieldInfo?

Advances once in canonical field order. Return: Next descriptor or none.

PropertyView

pub final class PropertyView

Borrows one property-table selection.

PropertyView.CreateIterator

pub readonly fn CreateIterator() -> PropertyIterator

Starts independent property traversal. Return: Allocation-free cursor.

PropertyIterator

pub final class PropertyIterator

Owns one property-table cursor.

PropertyIterator.Next

pub fn Next() -> PropertyInfo?

Advances once in canonical property order. Return: Next descriptor or none.

MethodView

pub final class MethodView

Borrows one method-table selection.

MethodView.CreateIterator

pub readonly fn CreateIterator() -> MethodIterator

Starts independent method traversal. Return: Allocation-free cursor.

MethodIterator

pub final class MethodIterator

Owns one method-table cursor.

MethodIterator.Next

pub fn Next() -> MethodInfo?

Advances once in canonical method order. Return: Next descriptor or none.

TypeAttributeView

pub final class TypeAttributeView

Borrows direct attributes of one type descriptor.

TypeAttributeView.CreateIterator

pub readonly fn CreateIterator() -> TypeAttributeIterator

Starts an independent direct-attribute traversal. Return: Allocation-free cursor.

TypeAttributeIterator

pub final class TypeAttributeIterator

Owns one direct-attribute cursor for a type descriptor.

TypeAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in direct attribute declaration order. Return: Next descriptor or none.

ParameterAttributeView

pub final class ParameterAttributeView

Borrows direct attributes of one parameter descriptor.

ParameterAttributeView.CreateIterator

pub readonly fn CreateIterator() -> ParameterAttributeIterator

Starts an independent direct-attribute traversal. Return: Allocation-free cursor.

ParameterAttributeIterator

pub final class ParameterAttributeIterator

Owns one direct-attribute cursor for a parameter descriptor.

ParameterAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in direct attribute declaration order. Return: Next descriptor or none.

FieldAttributeView

pub final class FieldAttributeView

Borrows direct attributes of one field descriptor.

FieldAttributeView.CreateIterator

pub readonly fn CreateIterator() -> FieldAttributeIterator

Starts an independent direct-attribute traversal. Return: Allocation-free cursor.

FieldAttributeIterator

pub final class FieldAttributeIterator

Owns one direct-attribute cursor for a field descriptor.

FieldAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in direct attribute declaration order. Return: Next descriptor or none.

PropertyAttributeView

pub final class PropertyAttributeView

Borrows direct attributes of one property descriptor.

PropertyAttributeView.CreateIterator

pub readonly fn CreateIterator() -> PropertyAttributeIterator

Starts an independent direct-attribute traversal. Return: Allocation-free cursor.

PropertyAttributeIterator

pub final class PropertyAttributeIterator

Owns one direct-attribute cursor for a property descriptor.

PropertyAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in direct attribute declaration order. Return: Next descriptor or none.

MethodAttributeView

pub final class MethodAttributeView

Borrows direct attributes of one method descriptor.

MethodAttributeView.CreateIterator

pub readonly fn CreateIterator() -> MethodAttributeIterator

Starts an independent direct-attribute traversal. Return: Allocation-free cursor.

MethodAttributeIterator

pub final class MethodAttributeIterator

Owns one direct-attribute cursor for a method descriptor.

MethodAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in direct attribute declaration order. Return: Next descriptor or none.

SiteEffectiveAttributeView

pub final class SiteEffectiveAttributeView

Borrows effective attributes from one site descriptor.

SiteEffectiveAttributeView.CreateIterator

pub readonly fn CreateIterator() -> SiteEffectiveAttributeIterator

Starts an independent effective-attribute traversal. Return: Allocation-free cursor.

SiteEffectiveAttributeIterator

pub final class SiteEffectiveAttributeIterator

Owns one effective-attribute cursor for a site descriptor.

SiteEffectiveAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in effective attribute order. Return: Next descriptor or none.

TypeEffectiveAttributeView

pub final class TypeEffectiveAttributeView

Borrows effective attributes from one type descriptor.

TypeEffectiveAttributeView.CreateIterator

pub readonly fn CreateIterator() -> TypeEffectiveAttributeIterator

Starts an independent effective-attribute traversal. Return: Allocation-free cursor.

TypeEffectiveAttributeIterator

pub final class TypeEffectiveAttributeIterator

Owns one effective-attribute cursor for a type descriptor.

TypeEffectiveAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in effective attribute order. Return: Next descriptor or none.

ParameterEffectiveAttributeView

pub final class ParameterEffectiveAttributeView

Borrows effective attributes from one parameter descriptor.

ParameterEffectiveAttributeView.CreateIterator

pub readonly fn CreateIterator() -> ParameterEffectiveAttributeIterator

Starts an independent effective-attribute traversal. Return: Allocation-free cursor.

ParameterEffectiveAttributeIterator

pub final class ParameterEffectiveAttributeIterator

Owns one effective-attribute cursor for a parameter descriptor.

ParameterEffectiveAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in effective attribute order. Return: Next descriptor or none.

FieldEffectiveAttributeView

pub final class FieldEffectiveAttributeView

Borrows effective attributes from one field descriptor.

FieldEffectiveAttributeView.CreateIterator

pub readonly fn CreateIterator() -> FieldEffectiveAttributeIterator

Starts an independent effective-attribute traversal. Return: Allocation-free cursor.

FieldEffectiveAttributeIterator

pub final class FieldEffectiveAttributeIterator

Owns one effective-attribute cursor for a field descriptor.

FieldEffectiveAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in effective attribute order. Return: Next descriptor or none.

PropertyEffectiveAttributeView

pub final class PropertyEffectiveAttributeView

Borrows effective attributes from one property descriptor.

PropertyEffectiveAttributeView.CreateIterator

pub readonly fn CreateIterator() -> PropertyEffectiveAttributeIterator

Starts an independent effective-attribute traversal. Return: Allocation-free cursor.

PropertyEffectiveAttributeIterator

pub final class PropertyEffectiveAttributeIterator

Owns one effective-attribute cursor for a property descriptor.

PropertyEffectiveAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in effective attribute order. Return: Next descriptor or none.

MethodEffectiveAttributeView

pub final class MethodEffectiveAttributeView

Borrows effective attributes from one method descriptor.

MethodEffectiveAttributeView.CreateIterator

pub readonly fn CreateIterator() -> MethodEffectiveAttributeIterator

Starts an independent effective-attribute traversal. Return: Allocation-free cursor.

MethodEffectiveAttributeIterator

pub final class MethodEffectiveAttributeIterator

Owns one effective-attribute cursor for a method descriptor.

MethodEffectiveAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in effective attribute order. Return: Next descriptor or none.

SiteAttributeView

pub final class SiteAttributeView

Borrows attributes authored at one canonical site.

SiteAttributeView.CreateIterator

pub readonly fn CreateIterator() -> SiteAttributeIterator

Starts independent direct-site traversal. Return: Allocation-free cursor.

SiteAttributeIterator

pub final class SiteAttributeIterator

Owns one direct-site attribute cursor.

SiteAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Advances in direct site order. Return: Next descriptor or none.

SiteFilteredAttributeView

pub final class SiteFilteredAttributeView<A>

Borrows direct attributes of one exact type from a site descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

SiteFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> SiteFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

SiteFilteredAttributeIterator

pub final class SiteFilteredAttributeIterator<A>

Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

SiteFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in direct order. Return: Existing descriptor or none.

SiteEffectiveFilteredAttributeView

pub final class SiteEffectiveFilteredAttributeView<A>

Borrows effective attributes of one exact type from a site descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

SiteEffectiveFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> SiteEffectiveFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

SiteEffectiveFilteredAttributeIterator

pub final class SiteEffectiveFilteredAttributeIterator<A>

Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

SiteEffectiveFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in effective order. Return: Existing descriptor or none.

TypeFilteredAttributeView

pub final class TypeFilteredAttributeView<A>

Borrows direct attributes of one exact type from a type descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

TypeFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> TypeFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

TypeFilteredAttributeIterator

pub final class TypeFilteredAttributeIterator<A>

Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

TypeFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in direct order. Return: Existing descriptor or none.

TypeEffectiveFilteredAttributeView

pub final class TypeEffectiveFilteredAttributeView<A>

Borrows effective attributes of one exact type from a type descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

TypeEffectiveFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> TypeEffectiveFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

TypeEffectiveFilteredAttributeIterator

pub final class TypeEffectiveFilteredAttributeIterator<A>

Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

TypeEffectiveFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in effective order. Return: Existing descriptor or none.

ParameterFilteredAttributeView

pub final class ParameterFilteredAttributeView<A>

Borrows direct attributes of one exact type from a parameter descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

ParameterFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> ParameterFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

ParameterFilteredAttributeIterator

pub final class ParameterFilteredAttributeIterator<A>

Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

ParameterFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in direct order. Return: Existing descriptor or none.

ParameterEffectiveFilteredAttributeView

pub final class ParameterEffectiveFilteredAttributeView<A>

Borrows effective attributes of one exact type from a parameter descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

ParameterEffectiveFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> ParameterEffectiveFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

ParameterEffectiveFilteredAttributeIterator

pub final class ParameterEffectiveFilteredAttributeIterator<A>

Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

ParameterEffectiveFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in effective order. Return: Existing descriptor or none.

FieldFilteredAttributeView

pub final class FieldFilteredAttributeView<A>

Borrows direct attributes of one exact type from a field descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

FieldFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> FieldFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

FieldFilteredAttributeIterator

pub final class FieldFilteredAttributeIterator<A>

Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

FieldFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in direct order. Return: Existing descriptor or none.

FieldEffectiveFilteredAttributeView

pub final class FieldEffectiveFilteredAttributeView<A>

Borrows effective attributes of one exact type from a field descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

FieldEffectiveFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> FieldEffectiveFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

FieldEffectiveFilteredAttributeIterator

pub final class FieldEffectiveFilteredAttributeIterator<A>

Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

FieldEffectiveFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in effective order. Return: Existing descriptor or none.

PropertyFilteredAttributeView

pub final class PropertyFilteredAttributeView<A>

Borrows direct attributes of one exact type from a property descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

PropertyFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> PropertyFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

PropertyFilteredAttributeIterator

pub final class PropertyFilteredAttributeIterator<A>

Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

PropertyFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in direct order. Return: Existing descriptor or none.

PropertyEffectiveFilteredAttributeView

pub final class PropertyEffectiveFilteredAttributeView<A>

Borrows effective attributes of one exact type from a property descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

PropertyEffectiveFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> PropertyEffectiveFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

PropertyEffectiveFilteredAttributeIterator

pub final class PropertyEffectiveFilteredAttributeIterator<A>

Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

PropertyEffectiveFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in effective order. Return: Existing descriptor or none.

MethodFilteredAttributeView

pub final class MethodFilteredAttributeView<A>

Borrows direct attributes of one exact type from a method descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

MethodFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> MethodFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

MethodFilteredAttributeIterator

pub final class MethodFilteredAttributeIterator<A>

Filters one direct attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

MethodFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in direct order. Return: Existing descriptor or none.

MethodEffectiveFilteredAttributeView

pub final class MethodEffectiveFilteredAttributeView<A>

Borrows effective attributes of one exact type from a method descriptor. A: Type used for exact StableId filtering of existing attribute descriptors.

MethodEffectiveFilteredAttributeView.CreateIterator

pub readonly fn CreateIterator() -> MethodEffectiveFilteredAttributeIterator<A>

Starts an independent filtered traversal. Return: Allocation-free cursor.

MethodEffectiveFilteredAttributeIterator

pub final class MethodEffectiveFilteredAttributeIterator<A>

Filters one effective attribute cursor by exact nominal type. A: Type used for exact StableId filtering of existing attribute descriptors.

MethodEffectiveFilteredAttributeIterator.Next

pub fn Next() -> AttributeInfo?

Finds the next matching attribute in effective order. Return: Existing descriptor or none.

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