diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 23315ea4..0ee168da 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -448,7 +448,7 @@ impl Tree { TreePropertyCursor::new(self, property_sheet, source) } - pub fn changed_ranges(&self, other: &Tree) -> impl Iterator { + pub fn changed_ranges(&self, other: &Tree) -> impl ExactSizeIterator { let mut count = 0; unsafe { let ptr = ffi::ts_tree_get_changed_ranges(self.0, other.0, &mut count as *mut _ as *mut u32); @@ -570,7 +570,7 @@ impl<'tree> Node<'tree> { unsafe { ffi::ts_node_child_count(self.0) as usize } } - pub fn children(&self) -> impl Iterator> { + pub fn children(&self) -> impl ExactSizeIterator> { let me = self.clone(); (0..self.child_count()) .into_iter() diff --git a/lib/binding_rust/util.rs b/lib/binding_rust/util.rs index df73f830..e62e371f 100644 --- a/lib/binding_rust/util.rs +++ b/lib/binding_rust/util.rs @@ -22,15 +22,22 @@ impl Iterator for CBufferIter { fn next(&mut self) -> Option { let i = self.i; - self.i += 1; if i >= self.count { None } else { + self.i += 1; Some(unsafe { *self.ptr.offset(i as isize) }) } } + + fn size_hint(&self) -> (usize, Option) { + let remaining = self.count - self.i; + (remaining, Some(remaining)) + } } +impl ExactSizeIterator for CBufferIter {} + impl Drop for CBufferIter { fn drop(&mut self) { unsafe { free_ptr(self.ptr as *mut c_void); }