Commit c7721bb368

Jakub Konka <kubkon@jakubkonka.com>
2020-06-11 22:31:08
Add custom format method for Preopen struct
1 parent e4a8598
Changed files (1)
lib
std
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