Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jedisct1/zig-bounded-array
BoundedArray module for Zig.
https://github.com/jedisct1/zig-bounded-array
array arrayvec bounded boundedarray tinyvec zig zig-lib zig-package ziglang
Last synced: about 1 month ago
JSON representation
BoundedArray module for Zig.
- Host: GitHub
- URL: https://github.com/jedisct1/zig-bounded-array
- Owner: jedisct1
- License: mit
- Created: 2023-11-22T17:18:28.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-05-21T13:39:03.000Z (6 months ago)
- Last Synced: 2024-10-05T04:34:16.112Z (about 2 months ago)
- Topics: array, arrayvec, bounded, boundedarray, tinyvec, zig, zig-lib, zig-package, ziglang
- Language: Zig
- Homepage:
- Size: 8.79 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BoundedArray for Zig
A `BoundedArray` is a structure containing a fixed-size array, as well as the length currently being used.
It can be used as a variable-length array that can be freely resized up to the size of the backing array.
If you're looking for a Zig equivalent to Rust's super useful `ArrayVec`, this is it.
It is useful to pass around small arrays whose exact size is only known at runtime, but whose maximum size is known at comptime, without requiring an `Allocator`.
Bounded arrays are easier and safer to use than maintaining buffers and active lengths separately, or involving structures that include pointers.
They can also be safely copied like any value, as they don't use any internal pointers.
```zig
var actual_size = 32;
var a = try BoundedArray(u8, 64).init(actual_size);
var slice = a.slice(); // a slice of the 64-byte array
var a_clone = a; // creates a copy - the structure doesn't use any internal pointers
```