Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › json/ › static.zig › fillDefaultStructValues
fillDefaultStructValues
static.fillDefaultStructValues
fn fillDefaultStructValues (comptime T : type , r : *T , fields_seen : *[@typeInfo (T ).@"struct" .field_names .len ]bool ) !void
File
Code
fn fillDefaultStructValues (comptime T : type , r : *T , fields_seen : *[@typeInfo (T ).@"struct" .field_names .len ]bool ) !void {
const info = @typeInfo (T ).@"struct" ;
inline for (
info .field_names ,
info .field_types ,
info .field_attrs ,
0 ..,
) |field_name , field_type , field_attrs , i | {
if (!fields_seen [i ]) {
if (field_attrs .defaultValue (field_type )) |default | {
@field (r , field_name ) = default ;
} else {
return error .MissingField ;
}
}
}
}