diff --git a/cli/src/tests/language_test.rs b/cli/src/tests/language_test.rs index f8a4653f..9880a9a3 100644 --- a/cli/src/tests/language_test.rs +++ b/cli/src/tests/language_test.rs @@ -27,7 +27,7 @@ fn test_lookahead_iterator() { assert_ne!(cursor.node().grammar_id(), cursor.node().kind_id()); let expected_symbols = ["identifier", "block_comment", "line_comment"]; - let lookahead = language.lookahead_iterator(next_state).unwrap(); + let mut lookahead = language.lookahead_iterator(next_state).unwrap(); assert_eq!(lookahead.language(), language); assert!(lookahead.iter_names().eq(expected_symbols)); diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 8e6b091a..461c9557 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -90,6 +90,7 @@ pub struct Parser(NonNull); /// A stateful object that is used to look up symbols valid in a specific parse state #[doc(alias = "TSLookaheadIterator")] pub struct LookaheadIterator(NonNull); +struct LookaheadNamesIterator<'a>(&'a mut LookaheadIterator); /// A type of log message. #[derive(Debug, PartialEq, Eq)] @@ -1525,7 +1526,7 @@ impl LookaheadIterator { /// This returns `true` if the language was set successfully and `false` /// otherwise. #[doc(alias = "ts_lookahead_iterator_reset")] - pub fn reset(&self, language: Language, state: u16) -> bool { + pub fn reset(&mut self, language: Language, state: u16) -> bool { unsafe { ffi::ts_lookahead_iterator_reset(self.0.as_ptr(), language.0, state) } } @@ -1534,19 +1535,17 @@ impl LookaheadIterator { /// This returns `true` if the iterator was reset to the given state and `false` /// otherwise. #[doc(alias = "ts_lookahead_iterator_reset_state")] - pub fn reset_state(&self, state: u16) -> bool { + pub fn reset_state(&mut self, state: u16) -> bool { unsafe { ffi::ts_lookahead_iterator_reset_state(self.0.as_ptr(), state) } } /// Iterate symbol names. - pub fn iter_names<'a>(&'a self) -> impl Iterator + 'a { - NameLookaheadIterator(&self) + pub fn iter_names(&mut self) -> impl Iterator + '_ { + LookaheadNamesIterator(self) } } -struct NameLookaheadIterator<'a>(&'a LookaheadIterator); - -impl<'a> Iterator for NameLookaheadIterator<'a> { +impl Iterator for LookaheadNamesIterator<'_> { type Item = &'static str; #[doc(alias = "ts_lookahead_iterator_advance")]