37 lines
981 B
Zig
37 lines
981 B
Zig
const std = @import("std");
|
|
|
|
const defaultString = "deef";
|
|
const structOfString = struct {
|
|
first: []const u8 = defaultString,
|
|
last: []const u8 = defaultString,
|
|
};
|
|
|
|
const listOfStruct = std.MultiArrayList(structOfString);
|
|
|
|
const testStrings = [_][]const u8{
|
|
"foo",
|
|
"bar",
|
|
"baz",
|
|
"foz"
|
|
};
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
var list = listOfStruct{};
|
|
defer list.deinit(gpa.allocator());
|
|
|
|
for(testStrings, 0..) |line, idx| {
|
|
const paddedLine = try std.fmt.allocPrint(gpa.allocator(), "{s: ^10}", .{line});
|
|
const new = switch(idx) {
|
|
0 => structOfString{.first = paddedLine},
|
|
else => structOfString{},
|
|
};
|
|
std.debug.print("new: {s}\n", .{new.first});
|
|
try list.append(gpa.allocator(), new);
|
|
}
|
|
for(list.items(.first), list.items(.last)) |first, last| {
|
|
std.debug.print("existing: {s}, {s}\n", .{first, last});
|
|
}
|
|
}
|