Development · Evolving reference
VectorInsertionError
Returns both allocation failure and unconsumed element ownership.
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.
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 ↗