slicezig

How to create an empty slice of slices


How do I construct []const []const u8 without using an allocator?

I can do

var slice: []const []const u8 = undefined;
slice.len = 0;
// use slice

But there surely must be a better way.


Solution

  • You can do:

    var foo: []const []const u8 = &.{};
    

    I leave it to you to judge if this is better and by how much.