fn BoundedArrayAligned(comptime T: type, comptime alignment: u29, comptime buffer_capacity: usize) type

A structure with an array, length and alignment, that can be used as a slice.

Useful to pass around small explicitly-aligned arrays whose exact size is only known at runtime, but whose maximum size is known at comptime, without requiring an Allocator.

Parameters

T: type,
alignment: u29,
buffer_capacity: usize,

Fields

buffer: [buffer_capacity]T = undefined,
len: Len = 0,

Functions

fn addManyAsArray(self: *Self, comptime n: usize) error{Overflow}!*align(alignment) [n]T

Resize the slice, adding n new elements, which have undefined values. The r…

Resize the slice, adding n new elements, which have undefined values. The return value is a slice pointing to the uninitialized elements.

fn addOne(self: *Self) error{Overflow}!*T

Increase length by 1, returning a pointer to the new item.

fn addOneAssumeCapacity(self: *Self) *T

Increase length by 1, returning pointer to the new item. Asserts that there is …

Increase length by 1, returning pointer to the new item. Asserts that there is space for the new item.

fn append(self: *Self, item: T) error{Overflow}!void

Extend the slice by 1 element.

fn appendAssumeCapacity(self: *Self, item: T) void

Extend the slice by 1 element, asserting the capacity is already enough to stor…

Extend the slice by 1 element, asserting the capacity is already enough to store the new item.

fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void

Append a value to the slice n times. Allocates more memory as necessary.

fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void

Append a value to the slice n times. Asserts the capacity is enough.

fn appendSlice(self: *Self, items: []const T) error{Overflow}!void

Append the slice of items to the slice.

fn appendSliceAssumeCapacity(self: *Self, items: []const T) void

Append the slice of items to the slice, asserting the capacity is already enoug…

Append the slice of items to the slice, asserting the capacity is already enough to store the new items.

fn capacity(self: Self) usize

Return the maximum length of a slice.

fn constSlice(self: *const Self) []const align(alignment) T

View the internal array as a constant slice whose size was previously set.

fn ensureUnusedCapacity(self: Self, additional_count: usize) error{Overflow}!void

Check that the slice can hold at least additional_count items.

fn fromSlice(m: []const T) error{Overflow}!Self

Copy the content of an existing slice.

fn get(self: Self, i: usize) T

Return the element at index i of the slice.

fn init(len: usize) error{Overflow}!Self

Set the actual length of the slice. Returns error.Overflow if it exceeds the le…

Set the actual length of the slice. Returns error.Overflow if it exceeds the length of the backing array.

fn insert(self: *Self, i: usize, item: T) error{Overflow}!void

Insert item at index i by moving slice[n .. slice.len] to make room. This…

Insert item at index i by moving slice[n .. slice.len] to make room. This operation is O(N).

fn insertSlice(self: *Self, i: usize, items: []const T) error{Overflow}!void

Insert slice items at index i by moving slice[i .. slice.len] to make room…

Insert slice items at index i by moving slice[i .. slice.len] to make room. This operation is O(N).

fn orderedRemove(self: *Self, i: usize) T

Remove the element at index i, shift elements after index i forward, and re…

Remove the element at index i, shift elements after index i forward, and return the removed element. Asserts the slice has at least one item. This operation is O(N).

fn pop(self: *Self) T

Remove and return the last element from the slice. Asserts the slice has at lea…

Remove and return the last element from the slice. Asserts the slice has at least one item.

fn popOrNull(self: *Self) ?T

Remove and return the last element from the slice, or return null if the slic…

Remove and return the last element from the slice, or return null if the slice is empty.

fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) error{Overflow}!void

Replace range of elements slice[start..][0..len] with new_items. Grows slic…

Replace range of elements slice[start..][0..len] with new_items. Grows slice if len < new_items.len. Shrinks slice if len > new_items.len.

fn resize(self: *Self, len: usize) error{Overflow}!void

Adjust the slice’s length to len. Does not initialize added items if any.

fn set(self: *Self, i: usize, item: T) void

Set the value of the element at index i of the slice.

fn slice(self: anytype) switch (@TypeOf(&self.buffer)) {
            *align(alignment) [buffer_capacity]T => []align(alignment) T,
            *align(alignment) const [buffer_capacity]T => []align(alignment) const T,
            else => unreachable,
        }

View the internal array as a slice whose size was previously set.

fn swapRemove(self: *Self, i: usize) T

Remove the element at the specified index and return it. The empty slot is fill…

Remove the element at the specified index and return it. The empty slot is filled from the end of the slice. This operation is O(1).

fn unusedCapacitySlice(self: *Self) []align(alignment) T

Return a slice of only the extra capacity after items. This can be useful for w…

Return a slice of only the extra capacity after items. This can be useful for writing directly into it. Note that such an operation must be followed up with a call to resize()

fn writer(self: *Self) Writer

Initializes a writer which will write into the array.

Values

Writer
type