code: simplify direction parsing

This commit is contained in:
Isaac Freund
2020-07-15 13:02:58 +02:00
parent 1389b4a850
commit 8afe7c2c87
4 changed files with 13 additions and 22 deletions

View File

@ -20,17 +20,8 @@ const std = @import("std");
const Seat = @import("Seat.zig");
pub const Direction = enum {
Next,
Prev,
pub fn parse(str: []const u8) error{InvalidDirection}!Direction {
return if (std.mem.eql(u8, str, "next"))
Direction.Next
else if (std.mem.eql(u8, str, "previous"))
Direction.Prev
else
error.InvalidDirection;
}
next,
previous,
};
// TODO: this could be replaced with a comptime hashmap