diff options
author | Manlio Perillo <manlio.perillo@gmail.com> | 2023-05-06 11:50:42 +0200 |
---|---|---|
committer | Manlio Perillo <manlio.perillo@gmail.com> | 2023-05-06 11:50:42 +0200 |
commit | be43e2d010b65e0fb16f96cde3161d38fe535c31 (patch) | |
tree | 36c91c3a450c0076c4ff8e948f68af8c0dd0bc95 /build.zig | |
parent | 1c73ad29a7c76ffd937911906d5367e4a78fb161 (diff) |
build: make `Exercise.hint` optional
Use an optional type, instead of an empty string, since it is more
idiomatic.
Diffstat (limited to 'build.zig')
-rw-r--r-- | build.zig | 16 |
1 files changed, 5 insertions, 11 deletions
@@ -25,7 +25,7 @@ pub const Exercise = struct { output: []const u8, /// This is an optional hint to give if the program does not succeed. - hint: []const u8 = "", + hint: ?[]const u8 = null, /// By default, we verify output against stderr. /// Set this to true to check stdout instead. @@ -254,22 +254,16 @@ const ZiglingStep = struct { } const exe_path = self.compile(prog_node) catch { - if (self.exercise.hint.len > 0) { - print("\n{s}HINT: {s}{s}", .{ - bold_text, self.exercise.hint, reset_text, - }); - } + if (self.exercise.hint) |hint| + print("\n{s}HINT: {s}{s}", .{ bold_text, hint, reset_text }); self.help(); std.os.exit(1); }; self.run(exe_path, prog_node) catch { - if (self.exercise.hint.len > 0) { - print("\n{s}HINT: {s}{s}", .{ - bold_text, self.exercise.hint, reset_text, - }); - } + if (self.exercise.hint) |hint| + print("\n{s}HINT: {s}{s}", .{ bold_text, hint, reset_text }); self.help(); std.os.exit(1); |