SharedCreationError
Owns a payload that could not acquire shared storage and its allocation reason.
Module std.memory
import std.memory;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
SharedCreationError
pub class SharedCreationError<T> where T: MovableOwns a payload that could not acquire shared 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.shared_failure;
from std.memory import Shared, SharedCreationError, 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 = Shared<i32, RejectingAllocator>();
if !Empty.IsEmpty { return 1; }
Empty.Clear();
switch Shared<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;
}
}
}SharedCreationError.Reason
pub Reason: AllocationError;Explains why raw payload storage could not be acquired.
SharedCreationError.Value
pub Value: T;Owns the uninserted payload until explicitly moved or normally destroyed.
SharedCreationError.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.