| ... | @@ -50,12 +50,16 @@ pub fn ComptimeStringMap(comptime V: type, comptime kvs_list: anytype) type { | ... | @@ -50,12 +50,16 @@ pub fn ComptimeStringMap(comptime V: type, comptime kvs_list: anytype) type { |
| 50 | }; | 50 | }; |
| 51 | | 51 | |
| 52 | return struct { | 52 | return struct { |
| | 53 | /// Array of `struct { key: []const u8, value: V }` where `value` is `void{}` if `V` is `void`. |
| | 54 | /// Sorted by `key` length. |
| 53 | pub const kvs = precomputed.sorted_kvs; | 55 | pub const kvs = precomputed.sorted_kvs; |
| 54 | | 56 | |
| | 57 | /// Checks if the map has a value for the key. |
| 55 | pub fn has(str: []const u8) bool { | 58 | pub fn has(str: []const u8) bool { |
| 56 | return get(str) != null; | 59 | return get(str) != null; |
| 57 | } | 60 | } |
| 58 | | 61 | |
| | 62 | /// Returns the value for the key if any, else null. |
| 59 | pub fn get(str: []const u8) ?V { | 63 | pub fn get(str: []const u8) ?V { |
| 60 | if (str.len < precomputed.min_len or str.len > precomputed.max_len) | 64 | if (str.len < precomputed.min_len or str.len > precomputed.max_len) |
| 61 | return null; | 65 | return null; |