tree_sitter_language/language.rs
1#![no_std]
2/// `LanguageFn` wraps a C function that returns a pointer to a tree-sitter grammar.
3#[repr(transparent)]
4#[derive(Clone, Copy)]
5pub struct LanguageFn(unsafe extern "C" fn() -> *const ());
6
7impl LanguageFn {
8 /// Creates a [`LanguageFn`].
9 ///
10 /// # Safety
11 ///
12 /// Only call this with language functions generated from grammars
13 /// by the Tree-sitter CLI.
14 pub const unsafe fn from_raw(f: unsafe extern "C" fn() -> *const ()) -> Self {
15 Self(f)
16 }
17
18 /// Gets the function wrapped by this [`LanguageFn`].
19 #[must_use]
20 pub const fn into_raw(self) -> unsafe extern "C" fn() -> *const () {
21 self.0
22 }
23}