fix: children_by_field_id API to receive non option field id
This commit is contained in:
parent
fec7454ced
commit
d489d71623
1 changed files with 23 additions and 4 deletions
|
|
@ -1062,7 +1062,26 @@ impl<'tree> Node<'tree> {
|
|||
cursor: &'a mut TreeCursor<'tree>,
|
||||
) -> impl Iterator<Item = Node<'tree>> + '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<FieldId>,
|
||||
field_id: FieldId,
|
||||
cursor: &'a mut TreeCursor<'tree>,
|
||||
) -> impl Iterator<Item = Node<'tree>> + '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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue