Skip to content

std.mem.Allocator dupeZ to dupeSentinel #25285

@ANDRVV

Description

@ANDRVV

In the standard library, std.mem.Allocator has the dupeZ method, which provides no flexibility. Changing it to dupeSentinel could be a "Zig style" option that increases maintainability and code flexibility.

The dupeSentinel method should look like this:

pub fn dupeSentinel(allocator: Allocator, comptime T: type, m: []const u8, comptime s: T) Error![:s]T {
    const new_buf = try allocator.alloc(T, m.len + 1);
    @memcpy(new_buf[0..m.len], m);
    new_buf[m.len] = s;
    return new_buf[0..m.len :s];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions