tree-sitter/lib/language/language.rs
Liam Rosenfeld ea6b62cbc6 feat(language): derive Clone and Copy on LanguageFn
Allows a LanguageFn to be passed around and create multiple languages since Language::new consumes a LanguageFn

LanguageFn just wraps a function pointer, which already conforms to Copy so this is a simple addition.

(cherry picked from commit d60789afdc)
2024-09-03 12:15:56 -04:00

22 lines
643 B
Rust

#![no_std]
/// LanguageFn wraps a C function that returns a pointer to a tree-sitter grammer.
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct LanguageFn(unsafe extern "C" fn() -> *const ());
impl LanguageFn {
/// Creates a `LanguageFn`.
///
/// # 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)
}
/// Gets the function wrapped by this `LanguageFn`.
pub const fn into_raw(self) -> unsafe extern "C" fn() -> *const () {
self.0
}
}