From 9d875062f6e0cfb7a3a6b1b9c0bf118c4f65edbe Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Wed, 15 Feb 2023 15:56:14 +0100 Subject: [PATCH] Next video: show fmt.bufPrint. --- zig-impl/next-video.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zig-impl/next-video.md b/zig-impl/next-video.md index cb33cd6..30c51ab 100644 --- a/zig-impl/next-video.md +++ b/zig-impl/next-video.md @@ -56,6 +56,17 @@ Example: try writer.print("{s}/{s}", .{ self.rundir, service_name }); } +From + var buffer: [1000]u8 = undefined; + var fbs = std.io.fixedBufferStream(&buffer); + var writer = fbs.writer(); + try ctx.server_path("simple-context-test", writer); + var path = fbs.getWritten(); +To + var buffer: [1000]u8 = undefined; + var path = try std.fmt.bufPrint(&buffer, "{s}/{s}", .{ ctx.rundir, "simple-context-test" }); + + # Errors Double returning type => no need for specific return structures.