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

HashMapInsertionError

Owns both uninserted map inputs and their storage failure.

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.

HashMapInsertionError

pub final class HashMapInsertionError<K, V> where K: Movable where V: Movable

Owns both uninserted map inputs and their storage failure.

Logical map contents remain unchanged on allocation failure. Destruction releases both retained inputs through their ordinary lifecycle contracts. K: Original owned key type. V: Original owned value type.

Example

module example.hash_map_failure;
from std.collections import HashMap, HashPolicy;
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 = HashMap<u64, i32, HashPolicy<u64>, RejectingAllocator>(
        HashPolicy<u64>(Hash, Equals), default(RejectingAllocator));
    switch Values.TryInsert(7, 42) {
        case .Ok { Value = _ } => return 1;
        case .Err { Error = Failure } => {
            if Failure.Reason != .OutOfMemory || Failure.Key != 7 || Failure.Value != 42 { return 2; }
        }
    }
    if !Values.IsEmpty { return 3; }
    return 0;
}

HashMapInsertionError.Reason

pub Reason: AllocationError;

Exact recoverable allocation/layout failure.

HashMapInsertionError.Key

pub Key: K;

Owns the original uninserted key.

HashMapInsertionError.Value

pub Value: V;

Owns the original uninserted value.

HashMapInsertionError.init

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

Retains the failure reason and transfers both original inputs. Reason: Recoverable allocation or layout failure. Key: Uninserted key moved into the failure. Value: Uninserted value moved into the failure.

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