Michael Bartnett 31a2b8c364
std: Handle field struct defaults in std.mem.zeroInit
I originally started monkeying with this because std.mem.zeroes doesn't support sentinel-terminated const slices even with defaults in 0.10.x.

I see that std.mem.zeroes was modified in #13256 to allow setting these slices to "".

That got me partway to where I wanted, but there was still an issue fields whose types are structs, they wouldn't get their defaults.

So when iterating struct fields looking for default values, when there is no default value and the type is .Struct, it will delegate to a call to zeroInit.

* Initialize struct fields in zeroInit exactly once

In my changes, similar to the previous implementation, the priority order for fields being initialized is:

1. If the `init` argument is a tuple, the nth element corresponding to the nth field of the struct.
2. Otherwise, if the `init` argument is not a tuple, try to find a matching field name on `init` and use that field.
3. Is the field has a default value, initalize with that value.
4. Fall back to what the field would have been initialized to via a recursive call to `std.mem.zeroInit`.

But instead of initializing a default instance of the struct and then running multiple passes over it, the init method is chosen per-field and each field is initialized exactly once.
2023-01-16 14:24:47 +02:00
..
2023-01-11 15:39:49 -08:00
2022-12-13 15:04:03 -05:00
2023-01-12 03:46:15 -05:00
2022-12-18 01:46:09 -05:00
2022-12-13 13:14:20 +02:00
2022-12-09 21:57:17 +01:00
2022-11-04 00:09:27 +03:30
2023-01-04 01:26:50 +02:00
2023-01-02 16:57:15 -07:00
2023-01-02 16:57:15 -07:00
2023-01-08 22:16:16 -05:00
2022-12-13 13:14:20 +02:00
2022-12-31 20:49:02 -05:00
2023-01-11 15:39:48 -08:00
2022-09-11 23:18:43 -04:00
2023-01-03 12:47:48 +02:00
2023-01-11 15:39:48 -08:00
2023-01-04 01:26:50 +02:00
2022-04-15 17:01:01 -05:00
2023-01-06 18:52:39 -07:00
2022-12-21 17:02:53 +01:00