I propose that if you have a type T=struct{foo: U} and slice []T, accessing a slice with a field ([]T.foo) returns a slice []U with stride @sizeOf(T).
Example use case:
const entry = struct {
key: []const u8,
value: []u8,
}
const entrylist = std.ArrayList(entry);
fn getKeys(self: entrylist) [][]const u8 {
return self.toSlice().key; // returns slice with stride equal to @sizeOf(entry)
}
fn getKeyList(self: entrylist, allocator: *Allocator) []u8 {
return std.mem.join(allocator, ",", self.getKeys());
}
fn getValues(self: entrylist) [][]const u8 {
return self.toSlice().value; // returns slice with stride equal to @sizeOf(entry)
}
fn getValueList(self: entrylist, allocator: *Allocator) []u8 {
return std.mem.join(allocator, ",", self.getValues());
}
I propose that if you have a type
T=struct{foo: U}and slice[]T, accessing a slice with a field ([]T.foo) returns a slice[]Uwith stride@sizeOf(T).Example use case: