Function alt [src]
Helper for calling alternate format methods besides one named "format".
Prototype
pub fn alt( context: anytype, comptime func_name: @TypeOf(.enum_literal), ) Alt(@TypeOf(context), @field(@TypeOf(context), @tagName(func_name))) Parameters
func_name: @TypeOf(.enum_literal) Example
test alt {
const Example = struct {
number: u8,
pub fn other(ex: @This(), w: *Writer) Writer.Error!void {
try w.writeByte(ex.number);
}
};
const ex: Example = .{ .number = 'a' };
try expectFmt("a", "{f}", .{alt(ex, .other)});
} Source
pub fn alt(
context: anytype,
comptime func_name: @TypeOf(.enum_literal),
) Alt(@TypeOf(context), @field(@TypeOf(context), @tagName(func_name))) {
return .{ .data = context };
}