@@ -10,9 +10,9 @@ fn comptimeN(comptime T: type) usize {
1010 const encoding = objc .Encoding .init (T );
1111
1212 // Figure out how much space we need
13- var counting = std .io .countingWriter ( std . io . null_writer );
14- try std . fmt . format ( counting . writer (), "{ }" , .{encoding });
15- return counting . bytes_written ;
13+ var stream : std.io.Writer.Discarding = . init (&.{} );
14+ stream . writer . print ( "{f }" , .{encoding });
15+ return stream . count ;
1616 }
1717}
1818
@@ -23,8 +23,8 @@ pub fn comptimeEncode(comptime T: type) [comptimeN(T):0]u8 {
2323
2424 // Build our final signature
2525 var buf : [comptimeN (T ) + 1 ]u8 = undefined ;
26- var fbs = std .io .fixedBufferStream (buf [0 .. buf .len - 1 ]);
27- try std . fmt . format ( fbs .writer (), "{ }" , .{encoding });
26+ var fbs : std.io.Writer = . fixed (buf [0 .. buf .len - 1 ]);
27+ fbs .writer . print ( "{f }" , .{encoding });
2828 buf [buf .len - 1 ] = 0 ;
2929
3030 return buf [0 .. buf .len - 1 :0 ].* ;
@@ -107,9 +107,7 @@ pub const Encoding = union(enum) {
107107
108108 pub fn format (
109109 comptime self : Encoding ,
110- comptime fmt : []const u8 ,
111- options : std.fmt.FormatOptions ,
112- writer : anytype ,
110+ writer : * std.io.Writer ,
113111 ) ! void {
114112 switch (self ) {
115113 .char = > try writer .writeAll ("c" ),
@@ -133,7 +131,7 @@ pub const Encoding = union(enum) {
133131 .array = > | a | {
134132 try writer .print ("[{}" , .{a .len });
135133 const encode_type = init (a .arr_type );
136- try encode_type .format (fmt , options , writer );
134+ try encode_type .format (writer );
137135 try writer .writeAll ("]" );
138136 },
139137 .structure = > | s | {
@@ -152,7 +150,7 @@ pub const Encoding = union(enum) {
152150 try writer .writeAll ("=" );
153151 inline for (struct_info .@"struct" .fields ) | field | {
154152 const field_encode = init (field .type );
155- try field_encode .format (fmt , options , writer );
153+ try field_encode .format (writer );
156154 }
157155 }
158156
@@ -174,7 +172,7 @@ pub const Encoding = union(enum) {
174172 try writer .writeAll ("=" );
175173 inline for (union_info .@"union" .fields ) | field | {
176174 const field_encode = init (field .type );
177- try field_encode .format (fmt , options , writer );
175+ try field_encode .format (writer );
178176 }
179177 }
180178
@@ -209,7 +207,7 @@ pub const Encoding = union(enum) {
209207 }
210208
211209 // call this format function again, this time with the child type encoding
212- try encoding .format (fmt , options , writer );
210+ try encoding .format (writer );
213211 },
214212 else = > @compileError ("Pointer size not supported for encoding" ),
215213 }
@@ -219,10 +217,10 @@ pub const Encoding = union(enum) {
219217
220218 // Return type is first in a method encoding
221219 const ret_type_enc = init (fn_info .return_type .? );
222- try ret_type_enc .format (fmt , options , writer );
220+ try ret_type_enc .format (writer );
223221 inline for (fn_info .params ) | param | {
224222 const param_enc = init (param .type .? );
225- try param_enc .format (fmt , options , writer );
223+ try param_enc .format (writer );
226224 }
227225 },
228226 .unknown = > {},
@@ -400,7 +398,7 @@ test "**Union to Encoding.union encoding" {
400398
401399test "Fn to Encoding.function encoding" {
402400 const test_fn = struct {
403- fn add (_ : c.id , _ : c.SEL , _ : i8 ) callconv (.C ) void {}
401+ fn add (_ : c.id , _ : c.SEL , _ : i8 ) callconv (.c ) void {}
404402 };
405403
406404 try encodingMatchesType (@TypeOf (test_fn .add ), "v@:c" );
0 commit comments