mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
nodelist: implement iterators
This commit is contained in:
35
src/iterator/iterator.zig
Normal file
35
src/iterator/iterator.zig
Normal file
@@ -0,0 +1,35 @@
|
||||
const std = @import("std");
|
||||
|
||||
const generate = @import("../generate.zig");
|
||||
|
||||
pub const Interfaces = generate.Tuple(.{
|
||||
U32Iterator,
|
||||
});
|
||||
|
||||
pub const U32Iterator = struct {
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
length: u32,
|
||||
index: u32 = 0,
|
||||
|
||||
pub const Return = struct {
|
||||
value: u32,
|
||||
done: bool,
|
||||
};
|
||||
|
||||
pub fn _next(self: *U32Iterator) !Return {
|
||||
const i = self.index;
|
||||
if (i >= self.length) {
|
||||
return Return{
|
||||
.value = 0,
|
||||
.done = true,
|
||||
};
|
||||
}
|
||||
|
||||
self.index += 1;
|
||||
return Return{
|
||||
.value = i,
|
||||
.done = false,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user