I am simply trying to make a helper function to turn multi-line strings from separating with \n to \r\n for an http header to be formatted properly.
Here is the function:
test "Raw representation of multi-line-string" {
const multi =
\\I am on
\\multiple lines!!
;
const formatted_multi = comptime formatHeaderTemplate(multi);
const formatted =
"I am on\r\n" ++
"multiple lines!!";
//@compileLog(formatted_multi);
//@compileLog(formatted);
try std.testing.expect(std.mem.eql(u8, formatted_multi, formatted));
}
Here is my strange error:
$ zig test src/root.zig
src/root.zig:178:44: error: runtime value contains reference to comptime var
try std.testing.expect(std.mem.eql(u8, formatted_multi, formatted));
^~~~~~~~~~~~~~~
src/root.zig:178:44: note: comptime var pointers are not available at runtime
src/root.zig:183:38: note: 'runtime_value.ptr' points to comptime var declared here
var new_template: [size]u8 = undefined;
^~~~~~~~~
I understand that I am basically doing the same thing as returning a reference to a stack allocated array, but I’m not familiar with another way to do comptime manipulation of other comptime values.
I assume that I can use the stdlib functions like those in mem at comptime as well.
I just want to take the comptime string value of my template, replace its endings with different endings, and then leave it for my runtime code to use