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 i: usize = 0;
var it = self.faces.get(style).constIterator(0); var it = self.faces.get(style).constIterator(0);
while (it.next()) |entry_or_alias| { 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 .{ return .{
.style = style, .style = style,
.idx = @intCast(i), .idx = @intCast(i),
@ -215,7 +215,7 @@ pub fn hasCodepoint(
) bool { ) bool {
const list = self.faces.get(index.style); const list = self.faces.get(index.style);
if (index.idx >= list.count()) return false; 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{ 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 { pub fn unwrapNoAlias(self: *EntryOrAlias) ?*Entry {
return switch (self.*) { return switch (self.*) {
.entry => |*v| v, .entry => |*v| v,