Add unwrapConst, avoid constCast

This commit is contained in:
Daniel Wennberg
2025-07-17 17:26:37 -07:00
parent ce507f35df
commit 054b7325dc

View File

@ -189,7 +189,7 @@ pub fn getIndex(
var i: usize = 0;
var it = self.faces.get(style).constIterator(0);
while (it.next()) |entry_or_alias| {
if (@constCast(entry_or_alias).unwrap().hasCodepoint(cp, p_mode)) {
if (entry_or_alias.unwrapConst().hasCodepoint(cp, p_mode)) {
return .{
.style = style,
.idx = @intCast(i),
@ -215,7 +215,7 @@ pub fn hasCodepoint(
) bool {
const list = self.faces.get(index.style);
if (index.idx >= list.count()) return false;
return @constCast(list.at(index.idx)).unwrap().hasCodepoint(cp, p_mode);
return list.at(index.idx).unwrapConst().hasCodepoint(cp, p_mode);
}
pub const CompleteError = Allocator.Error || error{
@ -770,6 +770,13 @@ pub const EntryOrAlias = union(enum) {
};
}
pub fn unwrapConst(self: *const EntryOrAlias) *const Entry {
return switch (self.*) {
.entry => |*v| v,
.alias => |v| v,
};
}
pub fn unwrapNoAlias(self: *EntryOrAlias) ?*Entry {
return switch (self.*) {
.entry => |*v| v,