Type Function Formatter [src]
Creates a Formatter type from a format function. Wrapping data in Formatter(func) causes
the data to be formatted using the given function func. func must be of the following
form:
fn formatExample(
data: T,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void;
Prototype
pub fn Formatter(comptime formatFn: anytype) type
Source
pub fn Formatter(comptime formatFn: anytype) type {
const Data = @typeInfo(@TypeOf(formatFn)).@"fn".params[0].type.?;
return struct {
data: Data,
pub fn format(
self: @This(),
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) @TypeOf(writer).Error!void {
try formatFn(self.data, fmt, options, writer);
}
};
}