1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn stringToEnum(comptime E: type, str: ?string) ?E {
6 return std.meta.stringToEnum(E, str orelse return null);
7}
8
9test {
10 try std.testing.expect(stringToEnum(enum { A, B }, "A") == .A);
11}
12test {
13 try std.testing.expect(stringToEnum(enum { A, B }, "B") == .B);
14}
15test {
16 try std.testing.expect(stringToEnum(enum { A, B }, "C") == null);
17}
18test {
19 try std.testing.expect(stringToEnum(enum { A, B }, null) == null);
20}