2024-05-30 16:05:30 +08:00
|
|
|
#![no_std]
|
2024-09-07 20:13:58 -04:00
|
|
|
/// `LanguageFn` wraps a C function that returns a pointer to a tree-sitter grammer.
|
2024-02-23 14:12:58 -08:00
|
|
|
#[repr(transparent)]
|
2024-09-02 21:12:17 -04:00
|
|
|
#[derive(Clone, Copy)]
|
2024-02-23 14:12:58 -08:00
|
|
|
pub struct LanguageFn(unsafe extern "C" fn() -> *const ());
|
|
|
|
|
|
|
|
|
|
impl LanguageFn {
|
2024-09-07 20:13:58 -04:00
|
|
|
/// Creates a [`LanguageFn`].
|
2024-02-23 14:12:58 -08:00
|
|
|
///
|
|
|
|
|
/// # Safety
|
|
|
|
|
///
|
|
|
|
|
/// Only call this with language functions generated from grammars
|
|
|
|
|
/// by the Tree-sitter CLI.
|
|
|
|
|
pub const unsafe fn from_raw(f: unsafe extern "C" fn() -> *const ()) -> Self {
|
|
|
|
|
Self(f)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-07 20:13:58 -04:00
|
|
|
/// Gets the function wrapped by this [`LanguageFn`].
|
|
|
|
|
#[must_use]
|
2024-02-23 14:12:58 -08:00
|
|
|
pub const fn into_raw(self) -> unsafe extern "C" fn() -> *const () {
|
|
|
|
|
self.0
|
|
|
|
|
}
|
|
|
|
|
}
|