Skip to content

Instantly share code, notes, and snippets.

@ranjian0
Created June 10, 2023 21:21
Show Gist options
  • Save ranjian0/2bf4baf570f18d03a396394853cf32c3 to your computer and use it in GitHub Desktop.
Save ranjian0/2bf4baf570f18d03a396394853cf32c3 to your computer and use it in GitHub Desktop.
const std = @import("std");
const Foo = struct {
const Self = @This();
bar:std.ArrayList(u8) = undefined,
pub fn init(allocator: std.mem.Allocator) Foo {
var bar = std.ArrayList(u8).init(allocator);
return .{ .bar = bar };
}
pub fn deinit(self: Self) void {
self.bar.deinit();
}
};
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var foo = Foo.init(allocator);
defer foo.deinit();
std.debug.print("Hello, World! {}\n", .{foo.bar});
try foo.bar.append(10);
std.debug.print("Hello, World! {}\n", .{foo.bar});
}
@ranjian0
Copy link
Author

To print a nice array

    std.debug.print("Hello, World! {any}\n", .{foo.bar.items});
    try foo.bar.append(10);
    std.debug.print("Hello, World! {any}\n", .{foo.bar.items});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment