Skip to content

Bike-shedding names and API #4

@tristanpemble

Description

@tristanpemble

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 represents
  • ResizableArray -> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions