Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

Indexable

Defines the exact canonical read indexing protocol used by `Base[Index]`.

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

import std.collections;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

Indexable

pub concept Indexable<Self>

Defines the exact canonical read indexing protocol used by Base[Index].

Satisfaction is structural and compile-time-only. The operation returns an element place rather than copying an item, allocates nothing, and remains responsible for its own bounds policy.

Example

module example.indexable;
from std.collections import Vector;
fn Main() -> i32 {
    var Values = Vector<i32>();
    if Values.TryPush(4) is .Err { Error = Failure } {
        return Failure.Value;
    }
    Values[0] = 9;
    let ReadOnly: readonly i32[] = Values.AsSlice();
    if ReadOnly[0] != 9 {
        return 1;
    }
    return 0;
}

Indexable.Item

associated type Item;

Identifies the referenced element type.

Indexable.At

requires readonly fn At(Index: usize) -> Item&;

Borrows one checked element with read-only access. Index: Zero-based element index. Return: Read-only element reference tied to the source lifetime.

WritableIndexable

pub concept WritableIndexable<Self>

Extends canonical indexing with writable element-place access. Self: Mutable source type satisfying both exact At requirements.

WritableIndexable.Item

associated type Item;

Identifies the shared read/write element type.

WritableIndexable.At

requires readonly fn At(Index: usize) -> Item&;

Borrows one checked read-only element. Index: Zero-based index. Return: Read-only reference.

WritableIndexable.At

requires fn At(Index: usize) -> mut Item&;

Borrows one checked writable element. Index: Zero-based index. Return: Writable reference.

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