Storage

struct Storage<Element>

A reference-counted raw allocation interpreted as contiguous Element slots.

The type stores capacity nowhere: callers own all bounds and initialization invariants. get requires an initialized slot; set may initialize reserved storage. Prefer Array unless implementing a core container.

Properties

let base: RawPtr

The base address of the storage allocation.

Methods

func get(_ index: Int) -> &Element

Borrows the initialized element at index; bounds are the caller's responsibility.

View Source
pub func get(_ index: Int) -> &Element {
	let ptr: RawPtr = #_ir(self.base, index) { %? = gep Element $0 $1 }
	_load<Element>(ptr: ptr)
}

func set(index: Int, consume value: Element) -> Void

Stores value at index; the slot's initialization state is the caller's responsibility.

View Source
pub func set(index: Int, consume value: Element) -> Void {
	let ptr: RawPtr = #_ir(self.base, index) { %? = gep Element $0 $1 }
	_store<Element>(ptr: ptr, value: value)
}