Skip to content

Specify broader lifetime for Children::top() result#74

Open
tomekb234 wants to merge 1 commit intoy21:masterfrom
tomekb234:tag_children_top_lifetime
Open

Specify broader lifetime for Children::top() result#74
tomekb234 wants to merge 1 commit intoy21:masterfrom
tomekb234:tag_children_top_lifetime

Conversation

@tomekb234
Copy link

@tomekb234 tomekb234 commented Oct 28, 2025

The function Children::top() in parser/tag.rs returns a reference to RawChildren without a specified lifetime, so the lifetime of &self is implicitly used. This is too restrictive because the reference points to data which is valid within the potentially broader 'b lifetime.

This small patch fixes this problem.

The change allows writing (without unsafe hacks) for example the following convenience function:

fn iter_node_children<'a, 'b>(parser: &'b Parser<'a>, node: &'b Node<'a>) -> impl Iterator<Item = &'b Node<'a>> {
    node.children()
        .map(|children| children.top().iter().map(|handle| handle.get(parser).unwrap()))
        .into_iter()
        .flatten()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant