nupp.mem.array

Owned contiguous arrays of one scalar or struct type.

const array = nupp.mem.array

do
    const values = array.scalar(array.uint32, 4)
    const writable = values:write()

    writable[1] = 42
    nupp.drop(writable)

    print(values:read()[1])
end -- the array is released here

The array owns its storage and releases it at the end of the scope that holds it. Reading and writing it are the nupp.mem.span operations, so every index is checked against the count the array carries.

Module contents

Types

TypeKindDescription
Arrayrecord
BytesrecordOwned bytes, with the same checked view vocabulary as scalar arrays.
Scalarrecord

Functions

FunctionKindDescription
bytesfunctionAllocates zeroed bytes without treating the storage-only uint8 as a value type.
newArrayfunctionAllocates zeroed storage with the struct witness's physical layout.
scalarfunctionAllocates zeroed storage for the selected scalar element type.

Types#

Arrayrecord#

record array.Array<T> ...

Type parameters

NameDescription
T

Members

NameKindDescription
pointerfield
countfield
readmethod
writemethod

pointerfield#

pointer: T[?]
@private@readonly

countfield#

count: integer
@readonly

readmethod#

read: function(borrows self: Array<T>): Span<T> borrows (self)
Arguments
NameTypeDescription
borrows selfArray<T>
Returns
TypeDescription
Span<T> borrows (self)

writemethod#

write: function(exclusive self: Array<T>): Writable<T> borrows (self)
Arguments
NameTypeDescription
exclusive selfArray<T>
Returns
TypeDescription
Writable<T> borrows (self)

Bytesrecord#

record array.Bytes ...

Owned bytes, with the same checked view vocabulary as scalar arrays.

Members

NameKindDescription
pointerfield
countfield
readmethod
writemethod

pointerfield#

@private@readonly

countfield#

count: integer
@readonly

readmethod#

read: function read(borrows self): ByteSpan
Arguments
NameTypeDescription
borrows selfany
Returns
TypeDescription
ByteSpan

writemethod#

write: function write(exclusive self): Writable<uint8>
Arguments
NameTypeDescription
exclusive selfany
Returns
TypeDescription
Writable<uint8>

Scalarrecord#

record array.Scalar<T> ...

Type parameters

NameDescription
T

Members

NameKindDescription
physicalfield

physicalfield#

physical: string
@private@readonly

Functions#

array.bytesfunction#

function array.bytes(count: integer): array.Bytes

Allocates zeroed bytes without treating the storage-only uint8 as a value type.

Arguments

NameTypeDescription
countinteger

Returns

TypeDescription
array.Bytes

Raises

TypeCondition
string

when count is not a nonnegative integer

array.newArrayfunction#

function array.newArray<T>(takes witness: T, count: integer): array.Array<T>

Allocates zeroed storage with the struct witness's physical layout.

Type parameters

NameDescription
T

Arguments

NameTypeDescription
takes witnessT
countinteger

Returns

TypeDescription
array.Array<T>

Raises

TypeCondition
string

when count is not a nonnegative integer or exceeds the target's storage limit

array.scalarfunction#

function array.scalar<T>(borrows witness: array.Scalar<T>, count: integer): array.Array<T>

Allocates zeroed storage for the selected scalar element type.

Type parameters

NameDescription
T

Arguments

NameTypeDescription
borrows witnessarray.Scalar<T>
countinteger

Returns

TypeDescription
array.Array<T>

Raises

TypeCondition
string

when count is not a nonnegative integer or exceeds the target's storage limit