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

VectorInsertionError

Returns both allocation failure and unconsumed element ownership.

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.

VectorInsertionError

pub final class VectorInsertionError<T>

Returns both allocation failure and unconsumed element ownership.

A failed Vector insertion leaves the Vector unchanged and transfers the original item into this record. The caller may inspect Reason and explicitly move Value into another owner.

Example

module example.vector_insertion_error;
from std.collections import Vector;
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 Main() -> i32 {
    var Values = Vector<i32, RejectingAllocator>.WithAllocator(
        default(RejectingAllocator)
    );
    switch Values.TryInsert(0, 7) {
        case .Ok => return 1;
        case .Err { Error = Failure } => {
            if Failure.Reason != .OutOfMemory || Failure.Value != 7 ||
                !Values.IsEmpty {
                return 2;
            }
        }
    }
    return 0;
}

VectorInsertionError.Reason

pub Reason: AllocationError;

Stable allocation/layout failure identity.

VectorInsertionError.Value

pub Value: T;

Original unconsumed insertion value.

VectorInsertionError.init

pub init(Reason: AllocationError, mut Value: T)

Retains the insertion reason and transfers the original value. Reason: Exact allocation or layout failure. Value: Original item transferred into this error.

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