const c = @import("c"); const zpy = @import("../root.zig"); pub const Sequence = extern struct { const Self = @This(); pub const Fast = @import("fast.zig").Fast; data: c.PyObject, pub fn size(self: *Self) usize { return @intCast(c.PySequence_Size(@ptrCast(self))); } pub fn concat(self: *Self, tail: *Self) !*Self { return @ptrCast(c.PySequence_Concat( @ptrCast(self), @ptrCast(tail), ) orelse return error.Exception); } pub fn repeat(self: *Self, n: usize) !*Self { return @ptrCast(c.PySequence_Repeat( @ptrCast(self), @intCast(n), ) orelse return error.Exception); } pub fn inPlaceConcat(self: *Self, tail: *Self) !*Self { return @ptrCast(c.PySequence_InPlaceConcat( @ptrCast(self), @ptrCast(tail), ) orelse return error.Exception); } pub fn inPlaceRepeat(self: *Self, n: usize) !*Self { return @ptrCast(c.PySequence_InPlaceRepeat( @ptrCast(self), @intCast(n), ) orelse return error.Exception); } pub fn get(self: *Self, index: usize) ?*zpy.Object { return @ptrCast(c.PySequence_GetItem(@ptrCast(self), @intCast(index))); } pub fn getSlice(self: *Self, from: usize, to: usize) ?*Self { return @ptrCast(c.PySequence_GetSlice(@ptrCast(self), @intCast(from), @intCast(to))); } pub fn set(self: *Self, index: usize, value: *zpy.Object) !void { if (c.PySequence_SetItem(@ptrCast(self), @intCast(index), @ptrCast(value)) == -1) { return error.Exception; } } pub fn delete(self: *Self, index: usize) !void { if (c.PySequence_DelItem(@ptrCast(self), @intCast(index)) == -1) { return error.Exception; } } pub fn deleteSlice(self: *Self, from: usize, to: usize) !void { if (c.PySequence_DelSlice(@ptrCast(self), @intCast(from), @intCast(to)) == -1) { return error.Exception; } } pub fn count(self: *const Self, value: *zpy.Object) !usize { const result = c.PySequence_Count(@ptrCast(@constCast(self)), @ptrCast(value)); if (result == -1) { return error.Exception; } return result; } pub fn contains(self: *const Self, value: *zpy.Object) !bool { const result = c.PySequence_Contains(@ptrCast(@constCast(self)), @ptrCast(value)); if (result == -1) { return error.Exception; } return result != 0; } pub fn indexOf(self: *const Self, value: *zpy.Object) !usize { const index = c.PySequence_Index(@ptrCast(@constCast(self)), @ptrCast(value)); if (index == -1) { return error.Exception; } return index; } pub fn toList(self: *Self) !*zpy.List { return @ptrCast(c.PySequence_List(@ptrCast(self)) orelse return error.Exception); } pub fn toTuple(self: *Self) !*zpy.Tuple { return @ptrCast(c.PySequence_Tuple(@ptrCast(self)) orelse return error.Exception); } pub fn asFast(self: *Self) !*Fast { return @ptrCast(c.PySequence_Fast(@ptrCast(self), null) orelse return error.Exception); } pub fn asObject(self: *Self) *zpy.Object { return @ptrCast(self); } };