Created
June 10, 2023 21:21
-
-
Save ranjian0/2bf4baf570f18d03a396394853cf32c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To print a nice array