cursor.zig
pub usingnamespace Self;
pub const Self = packed struct(u8) {
pos: u6,
dir: u2,
fn to(self: Self) u8 {
return @bitCast(u8, self);
}
pub fn move(self: *Self) ?void {
const r = self.*;
@ptrCast(*i8, self).* += switch (self.dir) {
0 => -1,
1 => -8,
2 => 1,
3 => 8,
};
if (@popCount(r.to() ^ self.to()) > 3) return null;
}
pub fn mask(self: Self) u64 {
return @as(u64, 1) << self.pos;
}
comptime {
if (@sizeOf(Self) != 1) @compileLog("cursor size : ", @sizeOf(Self));
if (Self.to(.{ .pos = 1, .dir = 0 }) != 1) @compileError("wrong format");
}
};