fix: return LanguageRef in Parser::language

`ts_parser_language` doesn't do any refcounting, so we can't return the
resulting pointer as an owned Language object
This commit is contained in:
Mrmaxmeier 2024-10-17 21:44:08 +02:00 committed by GitHub
parent e87181ec9c
commit c03977a87e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -496,9 +496,9 @@ impl Parser {
/// Get the parser's current language.
#[doc(alias = "ts_parser_language")]
#[must_use]
pub fn language(&self) -> Option<Language> {
pub fn language(&self) -> Option<LanguageRef<'_>> {
let ptr = unsafe { ffi::ts_parser_language(self.0.as_ptr()) };
(!ptr.is_null()).then(|| Language(ptr))
(!ptr.is_null()).then_some(LanguageRef(ptr, PhantomData))
}
/// Get the parser's current logger.