-
Notifications
You must be signed in to change notification settings - Fork 1
Bike-shedding names and API #4
Copy link
Copy link
Open
Description
I am now leaning toward naming these two types:
ResizableStruct->StructuredSlice: I hint at it in the article I wrote but don't call it out explicitly, I just can't unsee the parallels between a slice and what the data structure here representsResizableArray->FlexibleArray: since it's clear this pattern most resembles C's flexible array members
usage then looks like this:
const Bytes = StructuredSlice(struct {
client: Client,
host: FlexibleArray(u8),
read_buf: FlexibleArray(u8),
write_buf: FlexibleArray(u8),
});
const bytes = Bytes.init(allocator, .{
.host = input.host_len,
.read_buf = input.read_buf_len,
.write_buf = input.write_buf_len,
});And with those names, I think we can then drop the resize method -- which is actually quite simple -- and let the user copy the data how they want to if they need to resize it, like they might when allocating a newly sized slice:
const new_bytes = Bytes.init(allocator, new_lens)
@memcpy(new_bytes.get(.host)[0..old_bytes.lens.host], old_bytes.get(.host));
// etc.I am also considering things like StructuredByteSlice and StructuredBytes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels