@@ -13,7 +13,7 @@ pub fn standardConfig(comptime List: type) bincode.FieldConfig(List) {
13
13
const list_info = arrayListInfo (List ).? ;
14
14
15
15
const S = struct {
16
- fn serialize (writer : anytype , data : anytype , params : bincode.Params ) anyerror ! void {
16
+ fn serialize (writer : anytype , data : List , params : bincode.Params ) ! void {
17
17
try bincode .write (writer , data .items .len , params );
18
18
for (data .items ) | item | try bincode .write (writer , item , params );
19
19
}
@@ -22,17 +22,21 @@ pub fn standardConfig(comptime List: type) bincode.FieldConfig(List) {
22
22
allocator : std.mem.Allocator ,
23
23
reader : anytype ,
24
24
params : Params ,
25
- ) anyerror ! List {
26
- const len = (try readIntAsLength (usize , reader , params )) orelse return error .ArrayListTooBig ;
25
+ ) ! List {
26
+ const maybe_len = try readIntAsLength (usize , reader , params );
27
+ const len = maybe_len orelse return error .ArrayListTooBig ;
27
28
28
29
var data : List = try List .initCapacity (allocator , len );
29
30
errdefer free (allocator , data );
30
31
31
- for (0.. len ) | _ | data .appendAssumeCapacity (try bincode .read (allocator , list_info .Elem , reader , params ));
32
+ for (0.. len ) | _ | {
33
+ const elem = try bincode .read (allocator , list_info .Elem , reader , params );
34
+ data .appendAssumeCapacity (elem );
35
+ }
32
36
return data ;
33
37
}
34
38
35
- fn free (allocator : std.mem.Allocator , data : anytype ) void {
39
+ fn free (allocator : std.mem.Allocator , data : List ) void {
36
40
var copy = data ;
37
41
for (copy .items ) | value | bincode .free (allocator , value );
38
42
switch (list_info .management ) {
@@ -51,9 +55,15 @@ pub fn standardConfig(comptime List: type) bincode.FieldConfig(List) {
51
55
52
56
/// Defaults the field of type `List` to an empty state on EOF.
53
57
pub fn defaultOnEofConfig (comptime List : type ) bincode.FieldConfig (List ) {
54
- const al_info = arrayListInfo (List ) orelse @compileError ("Expected std.ArrayList[Unmanaged]Aligned(T), got " ++ @typeName (List ));
58
+ const al_info = arrayListInfo (List ) orelse @compileError (
59
+ "Expected std.ArrayList[Unmanaged]Aligned(T), got " ++ @typeName (List ),
60
+ );
55
61
const S = struct {
56
- fn deserialize (allocator : std.mem.Allocator , reader : anytype , params : bincode.Params ) anyerror ! List {
62
+ fn deserialize (
63
+ allocator : std.mem.Allocator ,
64
+ reader : anytype ,
65
+ params : bincode.Params ,
66
+ ) ! List {
57
67
const len = if (bincode .readIntAsLength (usize , reader , params )) | maybe_len |
58
68
(maybe_len orelse return error .ArrayListTooBig )
59
69
else | err | switch (err ) {
@@ -74,7 +84,7 @@ pub fn defaultOnEofConfig(comptime List: type) bincode.FieldConfig(List) {
74
84
};
75
85
}
76
86
77
- fn free (allocator : std.mem.Allocator , data : anytype ) void {
87
+ fn free (allocator : std.mem.Allocator , data : List ) void {
78
88
var copy = data ;
79
89
for (copy .items ) | value | bincode .free (allocator , value );
80
90
switch (al_info .management ) {
0 commit comments