I encountered some behaviour which I don't understand and hope someone can explain it to me. Please check the following code snippet:
const std = @import("std");
pub fn main() !void {
std.log.info(try format(), .{}); // --> CASE 1
std.log.info("{s}", .{try format()}); // --> CASE 2
}
fn format() ![]const u8 {
var result: [10]u8 = undefined;
return try std.fmt.bufPrint(&result, "{d:0>4}-{d:0>2}-{d:0>2}", .{
2025,
1,
12,
});
}
The first line (CASE 1) prints the expected string "2025-01-12", but the second line (CASE 2) prints "12". I fail to understand why that is and would like to understand it (as I have a use case where I want to use the returned value as argument).