diff --git a/lib/std/http/headers.zig b/lib/std/http/headers.zig index a7a1464f99..cb232a3e3e 100644 --- a/lib/std/http/headers.zig +++ b/lib/std/http/headers.zig @@ -349,16 +349,14 @@ pub const Headers = struct { pub fn format( self: Self, comptime fmt: []const u8, - options: std.fmt.FormatOptions, - context: var, - comptime Errors: type, - output: fn (@TypeOf(context), []const u8) Errors!void, - ) Errors!void { + options: std.fmtstream.FormatOptions, + out_stream: var, + ) !void { for (self.toSlice()) |entry| { - try output(context, entry.name); - try output(context, ": "); - try output(context, entry.value); - try output(context, "\n"); + try out_stream.writeAll(entry.name); + try out_stream.writeAll(": "); + try out_stream.writeAll(entry.value); + try out_stream.writeAll("\n"); } } }; @@ -593,5 +591,5 @@ test "Headers.format" { \\foo: bar \\cookie: somevalue \\ - , try std.fmt.bufPrint(buf[0..], "{}", .{h})); + , try std.fmtstream.bufPrint(buf[0..], "{}", .{h})); } diff --git a/lib/std/io/out_stream.zig b/lib/std/io/out_stream.zig index 03901f6672..876a3b4701 100644 --- a/lib/std/io/out_stream.zig +++ b/lib/std/io/out_stream.zig @@ -25,7 +25,7 @@ pub fn OutStream( } pub fn print(self: Self, comptime format: []const u8, args: var) Error!void { - return std.fmt.format(self, Error, writeAll, format, args); + return std.fmtstream.format(self, format, args); } pub fn writeByte(self: Self, byte: u8) Error!void { diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 8fda3f647a..cef2bae98c 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -518,17 +518,15 @@ pub const Int = struct { pub fn format( self: Int, comptime fmt: []const u8, - options: std.fmt.FormatOptions, - context: var, - comptime FmtError: type, - output: fn (@TypeOf(context), []const u8) FmtError!void, + options: std.fmtstream.FormatOptions, + out_stream: var, ) FmtError!void { self.assertWritable(); // TODO look at fmt and support other bases // TODO support read-only fixed integers const str = self.toString(self.allocator.?, 10) catch @panic("TODO make this non allocating"); defer self.allocator.?.free(str); - return output(context, str); + return out_stream.print(str); } /// Returns -1, 0, 1 if |a| < |b|, |a| == |b| or |a| > |b| respectively. diff --git a/lib/std/net.zig b/lib/std/net.zig index de10a17640..9395d34f48 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -268,16 +268,14 @@ pub const Address = extern union { pub fn format( self: Address, comptime fmt: []const u8, - options: std.fmt.FormatOptions, - context: var, - comptime Errors: type, - comptime output: fn (@TypeOf(context), []const u8) Errors!void, + options: std.fmtstream.FormatOptions, + out_stream: var, ) !void { switch (self.any.family) { os.AF_INET => { const port = mem.bigToNative(u16, self.in.port); const bytes = @ptrCast(*const [4]u8, &self.in.addr); - try std.fmt.format(context, Errors, output, "{}.{}.{}.{}:{}", .{ + try std.fmtstream.format(out_stream, "{}.{}.{}.{}:{}", .{ bytes[0], bytes[1], bytes[2], @@ -288,7 +286,7 @@ pub const Address = extern union { os.AF_INET6 => { const port = mem.bigToNative(u16, self.in6.port); if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) { - try std.fmt.format(context, Errors, output, "[::ffff:{}.{}.{}.{}]:{}", .{ + try std.fmtstream.format(out_stream, "[::ffff:{}.{}.{}.{}]:{}", .{ self.in6.addr[12], self.in6.addr[13], self.in6.addr[14], @@ -308,30 +306,30 @@ pub const Address = extern union { break :blk buf; }, }; - try output(context, "["); + try out_stream.writeAll("["); var i: usize = 0; var abbrv = false; while (i < native_endian_parts.len) : (i += 1) { if (native_endian_parts[i] == 0) { if (!abbrv) { - try output(context, if (i == 0) "::" else ":"); + try out_stream.writeAll(if (i == 0) "::" else ":"); abbrv = true; } continue; } - try std.fmt.format(context, Errors, output, "{x}", .{native_endian_parts[i]}); + try std.fmtstream.format(out_stream, "{x}", .{native_endian_parts[i]}); if (i != native_endian_parts.len - 1) { - try output(context, ":"); + try out_stream.writeAll(":"); } } - try std.fmt.format(context, Errors, output, "]:{}", .{port}); + try std.fmtstream.format(out_stream, "]:{}", .{port}); }, os.AF_UNIX => { if (!has_unix_sockets) { unreachable; } - try std.fmt.format(context, Errors, output, "{}", .{&self.un.path}); + try std.fmtstream.format(out_stream, "{}", .{&self.un.path}); }, else => unreachable, } diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig index 087f965c4e..0dc3b3020d 100644 --- a/lib/std/net/test.zig +++ b/lib/std/net/test.zig @@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" { }; for (ips) |ip, i| { var addr = net.Address.parseIp6(ip, 0) catch unreachable; - var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; + var newIp = std.fmtstream.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); } @@ -51,7 +51,7 @@ test "parse and render IPv4 addresses" { "127.0.0.1", }) |ip| { var addr = net.Address.parseIp4(ip, 0) catch unreachable; - var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; + var newIp = std.fmtstream.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2])); } diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index 81d13ac1c3..5d9a678ce8 100644 --- a/lib/std/os/uefi.zig +++ b/lib/std/os/uefi.zig @@ -5,8 +5,6 @@ pub const protocols = @import("uefi/protocols.zig"); pub const status = @import("uefi/status.zig"); pub const tables = @import("uefi/tables.zig"); -const fmt = @import("std").fmt; - /// The EFI image's handle that is passed to its entry point. pub var handle: Handle = undefined; @@ -29,13 +27,11 @@ pub const Guid = extern struct { pub fn format( self: @This(), comptime f: []const u8, - options: fmt.FormatOptions, - context: var, - comptime Errors: type, - output: fn (@TypeOf(context), []const u8) Errors!void, + options: std.fmtstream.FormatOptions, + out_stream: var, ) Errors!void { if (f.len == 0) { - return fmt.format(context, Errors, output, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{ + return std.fmtstream.format(out_stream, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{ self.time_low, self.time_mid, self.time_high_and_version,