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

HashSetInsertionError

Owns one uninserted set key and its recoverable storage failure.

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

import std.collections;

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

HashSetInsertionError

pub final class HashSetInsertionError<K> where K: Movable

Owns one uninserted set key and its recoverable storage failure. K: Movable original key type.

Example

module example.hash_set_failure;
from std.collections import HashPolicy, HashSet;
from std.memory import AllocationError, Layout;
from std.prelude import Result;
struct RejectingAllocator {
    pub unsafe fn Allocate(StorageLayout: Layout) -> Result<mut byte*, AllocationError> {
        return .Err { Error = .OutOfMemory };
    }
    pub unsafe fn Free(Storage: mut byte*, StorageLayout: Layout) -> void {}
}
fn Hash(Key: readonly u64&) -> u64 { return Key; }
fn Equals(Left: readonly u64&, Right: readonly u64&) -> bool { return Left == Right; }
fn Main() -> i32 {
    var Values = HashSet<u64, HashPolicy<u64>, RejectingAllocator>(
        HashPolicy<u64>(Hash, Equals), default(RejectingAllocator));
    switch Values.TryInsert(42) {
        case .Ok { Value = _ } => return 1;
        case .Err { Error = Failure } => {
            if Failure.Reason != .OutOfMemory || Failure.Key != 42 { return 2; }
        }
    }
    if !Values.IsEmpty { return 3; }
    return 0;
}

HashSetInsertionError.Reason

pub Reason: AllocationError;

Exact allocation or layout failure.

HashSetInsertionError.Key

pub Key: K;

Owns the original uninserted key.

HashSetInsertionError.init

pub init(Reason: AllocationError, mut Key: K)

Stores the failure and transfers the original uninserted key. Reason: Recoverable allocation or layout failure. Key: Original key transferred without copying.

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