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

UniqueCreationError

Owns a payload that could not acquire unique storage and its allocation reason.

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

import std.memory;

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

UniqueCreationError

pub class UniqueCreationError<T> where T: Movable

Owns a payload that could not acquire unique storage and its allocation reason.

Error destruction releases Value normally; moving the error transfers it. No allocation is introduced by the error itself. Supplied allocator ownership is cleaned up by the failed creation path rather than returned here. T: Movable uninserted payload representation.

Example

module example.unique_failure;
from std.memory import Unique, UniqueCreationError, 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 { panic; }
}
fn Main() -> i32 {
    var Empty = Unique<i32, RejectingAllocator>(default(RejectingAllocator));
    if !Empty.IsEmpty { return 1; }
    Empty.Clear();
    switch Unique<i32, RejectingAllocator>.TryCreate(42, default(RejectingAllocator)) {
        case .Ok { Value = _ } => return 2;
        case .Err { Error = Error } => {
            if Error.Reason != .OutOfMemory || Error.Value != 42 { return 3; }
            return 0;
        }
    }
}

UniqueCreationError.Reason

pub Reason: AllocationError;

Explains why raw payload storage could not be acquired.

UniqueCreationError.Value

pub Value: T;

Owns the uninserted payload until explicitly moved or normally destroyed.

UniqueCreationError.init

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

Transfers the allocation reason and uninserted payload into an error owner. Reason: Exact raw allocation failure. Value: Owned input retained without another allocation.

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