diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index ae8e744d..2f8323df 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -1062,7 +1062,26 @@ impl<'tree> Node<'tree> { cursor: &'a mut TreeCursor<'tree>, ) -> impl Iterator> + 'a { let field_id = self.language().field_id_for_name(field_name); - self.children_by_field_id(field_id, cursor) + let mut done = field_id.is_none(); + if !done { + cursor.reset(*self); + cursor.goto_first_child(); + } + iter::from_fn(move || { + if !done { + while cursor.field_id() != field_id { + if !cursor.goto_next_sibling() { + return None; + } + } + let result = cursor.node(); + if !cursor.goto_next_sibling() { + done = true; + } + return Some(result); + } + None + }) } /// Iterate over this node's children with a given field id. @@ -1070,15 +1089,15 @@ impl<'tree> Node<'tree> { /// See also [Node::children_by_field_name]. pub fn children_by_field_id<'a>( &self, - field_id: Option, + field_id: FieldId, cursor: &'a mut TreeCursor<'tree>, ) -> impl Iterator> + 'a { cursor.reset(*self); cursor.goto_first_child(); let mut done = false; iter::from_fn(move || { - while !done { - while cursor.field_id() != field_id { + if !done { + while cursor.field_id() != Some(field_id) { if !cursor.goto_next_sibling() { return None; }