058_quiz7.patch 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. --- exercises/058_quiz7.zig 2023-10-03 22:15:22.125574535 +0200
  2. +++ answers/058_quiz7.zig 2023-10-05 20:04:07.106101152 +0200
  3. @@ -192,8 +192,8 @@
  4. // Oops! The hermit forgot how to capture the union values
  5. // in a switch statement. Please capture both values as
  6. // 'p' so the print statements work!
  7. - .place => print("{s}", .{p.name}),
  8. - .path => print("--{}->", .{p.dist}),
  9. + .place => |p| print("{s}", .{p.name}),
  10. + .path => |p| print("--{}->", .{p.dist}),
  11. }
  12. }
  13. };
  14. @@ -255,7 +255,7 @@
  15. // dereference and optional value "unwrapping" look
  16. // together. Remember that you return the address with the
  17. // "&" operator.
  18. - if (place == entry.*.?.place) return entry;
  19. + if (place == entry.*.?.place) return &entry.*.?;
  20. // Try to make your answer this long:__________;
  21. }
  22. return null;
  23. @@ -309,7 +309,7 @@
  24. //
  25. // Looks like the hermit forgot something in the return value of
  26. // this function. What could that be?
  27. - fn getTripTo(self: *HermitsNotebook, trip: []?TripItem, dest: *Place) void {
  28. + fn getTripTo(self: *HermitsNotebook, trip: []?TripItem, dest: *Place) TripError!void {
  29. // We start at the destination entry.
  30. const destination_entry = self.getEntry(dest);