How to copy a string in Zig?

Let’s have a look at the API of the standard library here and see if you find what you need: zig/lib/std/array_list.zig at master · ziglang/zig · GitHub

One option is you could do an appendSlice and make it very similar to what you are doing now:

    /// Append the slice of items to the list. Allocates more
        /// memory as necessary.
        /// Invalidates pointers if additional memory is needed.
        pub fn appendSlice(self: *Self, items: []const T) Allocator.Error!void {
            try self.ensureUnusedCapacity(items.len);
            self.appendSliceAssumeCapacity(items);
        }
2 Likes