From c7721bb3688dd5f69700c7a54b5ad30f8d1482e6 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 11 Jun 2020 22:31:08 +0200 Subject: [PATCH] Add custom format method for Preopen struct --- lib/std/fs/wasi.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig index 194e1d41a6..1b27227ddd 100644 --- a/lib/std/fs/wasi.zig +++ b/lib/std/fs/wasi.zig @@ -35,6 +35,14 @@ pub const Preopen = struct { .@"type" = .{ .Dir = path }, }; } + + pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: var) !void { + try out_stream.print("{{ .fd = {}, ", .{self.fd}); + switch (self.@"type") { + PreopenType.Dir => |path| try out_stream.print(".Dir = '{}'", .{path}), + } + return out_stream.print(" }}", .{}); + } }; /// Dynamically-sized array list of WASI preopens. This struct is a