aboutsummaryrefslogtreecommitdiff
path: root/lib/std/net.zig
diff options
context:
space:
mode:
authorBenjamin Feng <benjamin.feng@glassdoor.com>2020-02-29 15:35:18 -0600
committerBenjamin Feng <benjamin.feng@glassdoor.com>2020-03-12 10:26:28 -0500
commitc11d1055b868add74cc58f3bf745e93110ae6071 (patch)
tree4af26a48d8fa267a0d99cd06792e423708dadd21 /lib/std/net.zig
parent7364e965f473147a86cc62ccf47feac4878a15de (diff)
downloadzig-c11d1055b868add74cc58f3bf745e93110ae6071.tar.gz
zig-c11d1055b868add74cc58f3bf745e93110ae6071.zip
Integrated outstreams with new formatter
Diffstat (limited to 'lib/std/net.zig')
-rw-r--r--lib/std/net.zig22
1 files changed, 10 insertions, 12 deletions
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,
}