| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | const Partial = extras.Partial; |
| 5 | |
| 6 | pub fn joinPartial(comptime P: type, a: P, b: P) P { |
| 7 | var temp = a; |
| 8 | inline for (comptime std.meta.fieldNames(P)) |name| { |
| 9 | if (@field(b, name)) |val| @field(temp, name) = val; |
| 10 | } |
| 11 | return temp; |
| 12 | } |
| 13 | |
| 14 | test { |
| 15 | const S = struct { |
| 16 | a: u8 = 4, |
| 17 | b: u8 = 7, |
| 18 | c: u8 = 1, |
| 19 | }; |
| 20 | try std.testing.expect(std.meta.eql( |
| 21 | joinPartial( |
| 22 | Partial(S), |
| 23 | .{ .a = 5 }, |
| 24 | .{ .b = 9 }, |
| 25 | ), |
| 26 | .{ |
| 27 | .a = 5, |
| 28 | .b = 9, |
| 29 | .c = null, |
| 30 | }, |
| 31 | )); |
| 32 | } |