const Entry = struct {
actor: []const u8,
age: u8,
};
const entries = std.ArrayList(Entry);
entries.deinit();
while (entries.items.len > 0) {
// pop from entries and do stuff with it
}
Also the documentation does not show that items is a field too
Yup, @squeek502 is correct. Here’s an example that I hope helps:
// this is the type of the array list
const ArrayListType = std.ArrayList(u8);
// use whatever allocator you want - this is an instance of the type
const array_list_instance = ArrayListType.init(std.heap.page_allocator);
const n = array_list_instance.items.len;
Thanks for this. What would you say is the best way to navigate the documentation then?
Because Zig Documentation did not make it clear, that I am looking at the type and not an instance (although I would assume the type should have info about the field).
The best thing to look at would be the test cases, like this one for example:
The documentation isn’t great for generic types (i.e. functions that return a type) yet. You can click on the [src] link and look at the test blocks in the file, though.
To be fair, the documentation you reference does have the words, “Type Function” at the top. For me, it has taken some time for that term to sink in and what it implies. Still, I find myself spending more time than I would like spelunking the standard library source code. But I have every confidence that it will get better.