From 6a12fd62c17ea2e054456e71d2a02ac995aa617a Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 26 Nov 2023 21:14:09 -0800 Subject: [PATCH] std: make std.unicode.initComptime() a comptime-known function resolved a TODO :) --- lib/std/unicode.zig | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index e4ea066cd6..1c0c6b32ac 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -330,15 +330,12 @@ pub const Utf8View = struct { return Utf8View{ .bytes = s }; } - /// TODO: https://github.com/ziglang/zig/issues/425 - pub fn initComptime(comptime s: []const u8) Utf8View { - if (comptime init(s)) |r| { - return r; - } else |err| switch (err) { + pub inline fn initComptime(comptime s: []const u8) Utf8View { + return comptime if (init(s)) |r| r else |err| switch (err) { error.InvalidUtf8 => { @compileError("invalid utf8"); }, - } + }; } pub fn iterator(s: Utf8View) Utf8Iterator {