Make unimplemented size hint iterators return 0 instead of null

This commit is contained in:
Luuk Machielse 2025-12-09 19:12:19 +01:00
parent a9aaf6fd61
commit 5dc6daf2eb

View file

@ -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);