|
@@ -8,39 +8,40 @@
|
|
// We have the start of an error set, but we're missing the condition
|
|
// We have the start of an error set, but we're missing the condition
|
|
// "TooSmall". Please add it where needed!
|
|
// "TooSmall". Please add it where needed!
|
|
const MyNumberError = error{
|
|
const MyNumberError = error{
|
|
- TooBig,
|
|
|
|
- ???,
|
|
|
|
- TooFour,
|
|
|
|
|
|
+ TooBig,
|
|
|
|
+ TooSmall,
|
|
|
|
+ TooFour,
|
|
};
|
|
};
|
|
|
|
|
|
const std = @import("std");
|
|
const std = @import("std");
|
|
|
|
|
|
pub fn main() void {
|
|
pub fn main() void {
|
|
- const nums = [_]u8{ 2, 3, 4, 5, 6 };
|
|
|
|
-
|
|
|
|
- for (nums) |n| {
|
|
|
|
- std.debug.print("{}", .{n});
|
|
|
|
-
|
|
|
|
- const number_error = numberFail(n);
|
|
|
|
-
|
|
|
|
- if (number_error == MyNumberError.TooBig) {
|
|
|
|
- std.debug.print(">4. ", .{});
|
|
|
|
- }
|
|
|
|
- if (???) {
|
|
|
|
- std.debug.print("<4. ", .{});
|
|
|
|
- }
|
|
|
|
- if (number_error == MyNumberError.TooFour) {
|
|
|
|
- std.debug.print("=4. ", .{});
|
|
|
|
- }
|
|
|
|
|
|
+ const nums = [_]u8{ 2, 3, 4, 5, 6 };
|
|
|
|
+
|
|
|
|
+ for(nums) |n|{
|
|
|
|
+ std.debug.print("{}", .{n});
|
|
|
|
+
|
|
|
|
+ const number_error = numberFail(n);
|
|
|
|
+
|
|
|
|
+ if(number_error == MyNumberError.TooBig){
|
|
|
|
+ std.debug.print(">4. ", .{});
|
|
}
|
|
}
|
|
-
|
|
|
|
- std.debug.print("\n", .{});
|
|
|
|
|
|
+ if(number_error == MyNumberError.TooSmall){
|
|
|
|
+ std.debug.print("<4. ", .{});
|
|
|
|
+ }
|
|
|
|
+ if(number_error == MyNumberError.TooFour){
|
|
|
|
+ std.debug.print("=4. ", .{});
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ std.debug.print("\n", .{});
|
|
}
|
|
}
|
|
|
|
|
|
// Notice how this function can return any member of the MyNumberError
|
|
// Notice how this function can return any member of the MyNumberError
|
|
// error set.
|
|
// error set.
|
|
-fn numberFail(n: u8) MyNumberError {
|
|
|
|
- if (n > 4) return MyNumberError.TooBig;
|
|
|
|
- if (n < 4) return MyNumberError.TooSmall; // <---- this one is free!
|
|
|
|
- return MyNumberError.TooFour;
|
|
|
|
|
|
+fn numberFail(n: u8) MyNumberError{
|
|
|
|
+ if(n > 4){ return MyNumberError.TooBig; }
|
|
|
|
+ if(n < 4){ return MyNumberError.TooSmall; } // <---- this one is free!
|
|
|
|
+ return MyNumberError.TooFour;
|
|
}
|
|
}
|
|
|
|
+
|