silk/slot
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
Explicit initialization-state transitions for one slot selected from raw storage.
When to use
Use these operations with silk.raw-buffer while implementing a container. Application code
should prefer an initialized collection, which maintains the slot state on the caller's behalf.
Details
write changes an uninitialized slot to initialized. take and dropValue change it
back to uninitialized, while copy leaves an initialized Copy value in place. Consuming a
Slot<'storage, T> prevents reusing the same selection accidentally, but the container must still keep
its own initialization map.
Gotchas
Selecting an out-of-bounds slot, writing twice, or reading an uninitialized slot violates the raw-storage contract. Debug execution may diagnose these mistakes; portable code must not rely on a runtime check.
Examples
Copy and then take one initialized value
import silk.allocator { Allocator, OutOfMemoryError }
import silk.effect { Effect }
import silk.layout { Layout }
import silk.raw_buffer { RawBuffer }
import silk.slot { Slot }
effect fn build() -> i32
! OutOfMemoryError {
let mut allocator = Allocator.systemAllocatorProvider()
let acquiring = Allocator.allocate(Layout.of<i32>())
|> Effect.provideMut<Allocator>(&mut allocator)
let allocation = run acquiring
unsafe {
let mut buffer = RawBuffer.from<i32>(move allocation, 1)
let written = Slot.write(RawBuffer.slot(&mut buffer, 0), 21)
let copied = Slot.copy(RawBuffer.slot(&mut buffer, 0))
let taken = Slot.take(RawBuffer.slot(&mut buffer, 0))
return copied + taken
}
return 0
}
effect fn recover(error: OutOfMemoryError) -> i32 {
return 0
}
pub fn main() -> i32 {
return run Effect.catchAll(build(), recover)
}Import as Slot with import silk.slot { Slot }.
Public declarations: 1.
Slot
pub struct SlotThe owner of the slot operations.
Details
This struct carries no data and is never constructed by the library. Every operation is an
inherent member declared in impl Slot, so import silk.slot { Slot } is the one import that
reaches Slot.write(...) and the rest. It is unrelated to the builtin Slot<'storage, T> place type.
Associated function Slot.address
pub fn address<'storage, T>(slot: silk/core.Slot<'storage, T>) -> *mut TForms a non-null writable address without reading or initializing the selected storage.
Gotchas
This operation consumes the slot selection. The pointer holds no loan and keeps no storage alive. A later memory access must prove its own lifetime, initialization, and access requirements.
Associated function Slot.write
pub fn write<'storage, T>(slot: silk/core.Slot<'storage, T>, value: T) -> ()Moves one value into a selected uninitialized raw slot.
Gotchas
The slot must be in bounds and uninitialized. A second write without a state transition is invalid. The value must satisfy the unchanged slot type, including every payload lifetime.
Associated function Slot.take
pub fn take<'storage, T>(slot: silk/core.Slot<'storage, T>) -> TMoves a value out of a selected initialized raw slot and leaves the slot uninitialized.
Details
The result retains every lifetime inside T. It does not retain the slot selection itself.
Gotchas
The slot must be in bounds and initialized.
Associated function Slot.copy
pub fn copy<'storage, T>(slot: silk/core.Slot<'storage, T>) -> TCopies a Copy value from a selected initialized raw slot without changing its state.
Gotchas
The slot must be in bounds and initialized.
Associated function Slot.dropValue
pub fn dropValue<'storage, T>(slot: silk/core.Slot<'storage, T>) -> ()Drops a value in a selected initialized raw slot and leaves the slot uninitialized.
Gotchas
The slot must be in bounds and initialized.