aboutsummaryrefslogtreecommitdiff
path: root/lib/std/net.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-13 11:31:11 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-03-13 11:31:11 -0400
commit2dd920ee394d06b4a215720b6bf7f355dacfd96f (patch)
tree2824dec01eff04baacb30d724fdb8bb00ed14c0a /lib/std/net.zig
parenta9297f22671dff800821ff940395411f2adb8582 (diff)
parent4aae55b4ccf44fa3c2c2a81a6a34f3c898dece30 (diff)
downloadzig-2dd920ee394d06b4a215720b6bf7f355dacfd96f.tar.gz
zig-2dd920ee394d06b4a215720b6bf7f355dacfd96f.zip
Merge branch 'format-stream' of https://github.com/fengb/zig into fengb-format-stream
Diffstat (limited to 'lib/std/net.zig')
-rw-r--r--lib/std/net.zig20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/std/net.zig b/lib/std/net.zig
index de10a17640..c2328b9bd0 100644
--- a/lib/std/net.zig
+++ b/lib/std/net.zig
@@ -269,15 +269,13 @@ pub const Address = extern union {
self: Address,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
- context: var,
- comptime Errors: type,
- comptime output: fn (@TypeOf(context), []const u8) Errors!void,
+ 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.fmt.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.fmt.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.fmt.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.fmt.format(out_stream, "]:{}", .{port});
},
os.AF_UNIX => {
if (!has_unix_sockets) {
unreachable;
}
- try std.fmt.format(context, Errors, output, "{}", .{&self.un.path});
+ try std.fmt.format(out_stream, "{}", .{&self.un.path});
},
else => unreachable,
}