Function comptimePrint [src]

Prototype

pub inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8

Parameters

fmt: []const u8

Example

test comptimePrint { @setEvalBranchQuota(2000); try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptimePrint("{}", .{100}))); try std.testing.expectEqualSlices(u8, "100", comptimePrint("{}", .{100})); try std.testing.expectEqualStrings("30", comptimePrint("{d}", .{30.0})); try std.testing.expectEqualStrings("30.0", comptimePrint("{d:3.1}", .{30.0})); try std.testing.expectEqualStrings("0.05", comptimePrint("{d}", .{0.05})); try std.testing.expectEqualStrings("5e-2", comptimePrint("{e}", .{0.05})); }

Source

pub inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8 { comptime { var buf: [count(fmt, args):0]u8 = undefined; _ = bufPrint(&buf, fmt, args) catch unreachable; buf[buf.len] = 0; const final = buf; return &final; } }