mirror of
https://codeberg.org/kaasboteram/zig-iterating.git
synced 2025-12-15 09:43:14 +01:00
Make unimplemented size hint iterators return 0 instead of null
This commit is contained in:
parent
a9aaf6fd61
commit
5dc6daf2eb
1 changed files with 3 additions and 3 deletions
|
|
@ -98,8 +98,8 @@ pub fn Iterator(comptime Inner: type) type {
|
|||
return self.inner.reset();
|
||||
}
|
||||
|
||||
pub fn sizeHint(self: *const Self) ?usize {
|
||||
return if (capabilities.size_hint) self.inner.sizeHint() else null;
|
||||
pub fn sizeHint(self: *const Self) usize {
|
||||
return if (capabilities.size_hint) self.inner.sizeHint() else 0;
|
||||
}
|
||||
|
||||
pub fn map(
|
||||
|
|
@ -197,7 +197,7 @@ pub fn Iterator(comptime Inner: type) type {
|
|||
}
|
||||
|
||||
pub fn toOwnedSlice(self: Self, allocator: std.mem.Allocator) ![]const Item {
|
||||
var list: std.ArrayList(Item) = if (self.sizeHint()) |num| try .initCapacity(allocator, num) else .empty;
|
||||
var list: std.ArrayList(Item) = try .initCapacity(allocator, self.sizeHint());
|
||||
errdefer list.deinit(allocator);
|
||||
|
||||
try self.collectInto(&list, allocator);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue