@@ -13,7 +13,8 @@ pub const countingWriter = @import("io/counting_writer.zig").countingWriter;
13
13
pub const null_writer = NullWriter {};
14
14
15
15
pub const NullWriter = struct {
16
- pub fn write (_ : NullWriter , data : []const u8 ) error {}! usize {
16
+ pub const WriteError = error {};
17
+ pub fn write (_ : NullWriter , data : []const u8 ) WriteError ! usize {
17
18
return data .len ;
18
19
}
19
20
};
@@ -24,7 +25,7 @@ test "null_writer" {
24
25
25
26
pub fn Reader (comptime T : type ) type {
26
27
return struct {
27
- ReadError : type = error {} ,
28
+ ReadError : type = anyerror ,
28
29
read : fn (reader_ctx : T , buffer : []u8 ) anyerror ! usize ,
29
30
};
30
31
}
@@ -94,8 +95,6 @@ pub inline fn streamUntilDelimiter(
94
95
if (byte == delimiter ) return ;
95
96
try writeByte (writer_ctx , writer_impl , byte );
96
97
}
97
- // Can not throw `error.StreamTooLong` since there are no
98
- // boundary.
99
98
}
100
99
}
101
100
@@ -206,7 +205,6 @@ pub inline fn readStruct(
206
205
reader_impl : Impl (Reader , @TypeOf (reader_ctx )),
207
206
comptime T : type ,
208
207
) (reader_impl .ReadError || error {EndOfStream })! T {
209
- // Only extern and packed structs have defined in-memory layout.
210
208
comptime assert (@typeInfo (T ).Struct .layout != .Auto );
211
209
var res : [1 ]T = undefined ;
212
210
try readNoEof (reader_ctx , reader_impl , mem .sliceAsBytes (res [0.. ]));
@@ -231,11 +229,6 @@ pub inline fn readEnum(
231
229
comptime Enum : type ,
232
230
endian : std.builtin.Endian ,
233
231
) (reader_impl .ReadError || error { EndOfStream , InvalidValue })! Enum {
234
- const E = error {
235
- /// An integer was read, but it did not match any of the tags
236
- /// in the supplied enum.
237
- InvalidValue ,
238
- };
239
232
const type_info = @typeInfo (Enum ).Enum ;
240
233
const tag = try readInt (
241
234
reader_ctx ,
@@ -250,12 +243,12 @@ pub inline fn readEnum(
250
243
}
251
244
}
252
245
253
- return E .InvalidValue ;
246
+ return error .InvalidValue ;
254
247
}
255
248
256
249
pub fn Writer (comptime T : type ) type {
257
250
return struct {
258
- WriteError : type = error {} ,
251
+ WriteError : type = anyerror ,
259
252
write : fn (writer_ctx : T , bytes : []const u8 ) anyerror ! usize ,
260
253
};
261
254
}
@@ -327,19 +320,18 @@ pub fn writeStruct(
327
320
writer_impl : Impl (Writer , @TypeOf (writer_ctx )),
328
321
value : anytype ,
329
322
) writer_impl .WriteError ! void {
330
- // Only extern and packed structs have defined in-memory layout.
331
323
comptime assert (@typeInfo (@TypeOf (value )).Struct .layout != .Auto );
332
324
return writeAll (writer_ctx , writer_impl , mem .asBytes (& value ));
333
325
}
334
326
335
327
pub fn Seekable (comptime T : type ) type {
336
328
return struct {
337
- SeekError : type = error {} ,
329
+ SeekError : type = anyerror ,
338
330
339
331
seekTo : fn (seek_ctx : T , pos : u64 ) anyerror ! void ,
340
332
seekBy : fn (seek_ctx : T , amt : i64 ) anyerror ! void ,
341
333
342
- GetSeekPosError : type = error {} ,
334
+ GetSeekPosError : type = anyerror ,
343
335
344
336
getPos : fn (seek_ctx : T ) anyerror ! u64 ,
345
337
getEndPos : fn (seek_ctx : T ) anyerror ! u64 ,
0 commit comments