| ... | @@ -519,7 +519,7 @@ test "mem.secureZero" { | ... | @@ -519,7 +519,7 @@ test "mem.secureZero" { |
| 519 | /// Initializes all fields of the struct with their default value, or zero values if no default value is present. | 519 | /// Initializes all fields of the struct with their default value, or zero values if no default value is present. |
| 520 | /// If the field is present in the provided initial values, it will have that value instead. | 520 | /// If the field is present in the provided initial values, it will have that value instead. |
| 521 | /// Structs are initialized recursively. | 521 | /// Structs are initialized recursively. |
| 522 | pub fn defaultInit(comptime T: type, init: var) T { | 522 | pub fn zeroInit(comptime T: type, init: var) T { |
| 523 | comptime const Init = @TypeOf(init); | 523 | comptime const Init = @TypeOf(init); |
| 524 | | 524 | |
| 525 | switch (@typeInfo(T)) { | 525 | switch (@typeInfo(T)) { |
| ... | @@ -538,7 +538,7 @@ pub fn defaultInit(comptime T: type, init: var) T { | ... | @@ -538,7 +538,7 @@ pub fn defaultInit(comptime T: type, init: var) T { |
| 538 | if (@hasField(Init, field.name)) { | 538 | if (@hasField(Init, field.name)) { |
| 539 | switch (@typeInfo(field.field_type)) { | 539 | switch (@typeInfo(field.field_type)) { |
| 540 | .Struct => { | 540 | .Struct => { |
| 541 | @field(value, field.name) = defaultInit(field.field_type, @field(init, field.name)); | 541 | @field(value, field.name) = zeroInit(field.field_type, @field(init, field.name)); |
| 542 | }, | 542 | }, |
| 543 | else => { | 543 | else => { |
| 544 | @field(value, field.name) = @field(init, field.name); | 544 | @field(value, field.name) = @field(init, field.name); |
| ... | @@ -562,7 +562,7 @@ pub fn defaultInit(comptime T: type, init: var) T { | ... | @@ -562,7 +562,7 @@ pub fn defaultInit(comptime T: type, init: var) T { |
| 562 | } | 562 | } |
| 563 | } | 563 | } |
| 564 | | 564 | |
| 565 | test "mem.defaultInit" { | 565 | test "zeroInit" { |
| 566 | const I = struct { | 566 | const I = struct { |
| 567 | d: f64, | 567 | d: f64, |
| 568 | }; | 568 | }; |
| ... | @@ -575,7 +575,7 @@ test "mem.defaultInit" { | ... | @@ -575,7 +575,7 @@ test "mem.defaultInit" { |
| 575 | f: i64, | 575 | f: i64, |
| 576 | }; | 576 | }; |
| 577 | | 577 | |
| 578 | const s = defaultInit(S, .{ | 578 | const s = zeroInit(S, .{ |
| 579 | .a = 42, | 579 | .a = 42, |
| 580 | }); | 580 | }); |
| 581 | | 581 | |
| ... | @@ -585,7 +585,7 @@ test "mem.defaultInit" { | ... | @@ -585,7 +585,7 @@ test "mem.defaultInit" { |
| 585 | .c = .{ | 585 | .c = .{ |
| 586 | .d = 0, | 586 | .d = 0, |
| 587 | }, | 587 | }, |
| 588 | .e = [3]u8{0, 0, 0}, | 588 | .e = [3]u8{ 0, 0, 0 }, |
| 589 | .f = 0, | 589 | .f = 0, |
| 590 | }); | 590 | }); |
| 591 | } | 591 | } |