Hi, coming back to trying zig after more than a year, and there are so many changes.
I had this piece of code that would have a helper function to do comptime formatting over some other formatting function. this used to work
fn foo(writer: anytype, bar: []const []const u8) !void {
// some formatting
try std.fmt.format(writer, "this {s}", .{bar[0]});
}
pub fn buffComptimeFmt(
comptime buff_len: usize,
comptime fmt_func: anytype,
comptime fmt_func_args: anytype,
) []const u8 {
comptime {
// Creates the buffer and allocator
var buffer: [buff_len]u8 = undefined;
var stream = std.Io.fixedBufferStream(&buffer);
@call(
.compile_time,
fmt_func,
// Pass the buffer writer as argument together with needed func arguments
.{stream.writer()} ++ fmt_func_args,
) catch {
@compileError("No space left in buffer");
};
// Return from comptime to runtime
const written = stream.getWritten();
const final = written[0..written.len].*;
return &final;
}
}
Searching and searching i found what i would imagine would be the substitute with
var stream: std.Io.Writer = .fixed(&buffer);
and just pass stream instead of stream.writer() to @call, but this then fails with
src/lib/utils.zig:81:23: error: unable to evaluate comptime expression
.{stream} ++ fmt_func_args,
^~~~~~
src/lib/utils.zig:81:15: note: operation is runtime due to this operand
.{stream} ++ fmt_func_args,
^~~~~~
so how to make it comptime again?
also its probable the method stream.getWritten()has probably changed names too, but i havent looked into that yet and i will find it when the compilation stops failing with this and inmediatly fails there lol