binding_rust: Unbind nodes lifitime from a source for QueryCursor.matches

This commit is contained in:
Andrew Hlynskyi 2021-04-22 11:50:44 +03:00
parent b57266cbb8
commit 9c91affe56

View file

@ -1587,7 +1587,7 @@ impl Query {
}
}
impl QueryCursor {
impl<'a> QueryCursor {
/// Create a new cursor for executing a given query.
///
/// The cursor stores the state that is needed to iteratively search for matches.
@ -1606,12 +1606,12 @@ impl QueryCursor {
/// Each match contains the index of the pattern that matched, and a list of captures.
/// Because multiple patterns can match the same set of nodes, one match may contain
/// captures that appear *before* some of the captures from a previous match.
pub fn matches<'a, T: AsRef<[u8]>>(
pub fn matches<'tree: 'a, T: AsRef<[u8]>>(
&'a mut self,
query: &'a Query,
node: Node<'a>,
mut text_callback: impl FnMut(Node<'a>) -> T + 'a,
) -> impl Iterator<Item = QueryMatch<'a>> + 'a {
node: Node<'tree>,
mut text_callback: impl FnMut(Node<'tree>) -> T + 'a,
) -> impl Iterator<Item = QueryMatch<'tree>> + 'a {
let ptr = self.0.as_ptr();
unsafe { ffi::ts_query_cursor_exec(ptr, query.ptr.as_ptr(), node.0) };
std::iter::from_fn(move || loop {
@ -1633,7 +1633,7 @@ impl QueryCursor {
///
/// This is useful if don't care about which pattern matched, and just want a single,
/// ordered sequence of captures.
pub fn captures<'a, T: AsRef<[u8]>>(
pub fn captures<T: AsRef<[u8]>>(
&'a mut self,
query: &'a Query,
node: Node<'a>,