#![allow(dead_code)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(clippy::missing_const_for_fn)]
#[cfg(feature = "bindgen")]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
#[cfg(not(feature = "bindgen"))]
include!("./bindings.rs");
#[cfg(unix)]
#[cfg(feature = "std")]
extern "C" {
pub(crate) fn _ts_dup(fd: std::os::raw::c_int) -> std::os::raw::c_int;
}
#[cfg(windows)]
extern "C" {
pub(crate) fn _ts_dup(handle: *mut std::os::raw::c_void) -> std::os::raw::c_int;
}
use core::{marker::PhantomData, mem::ManuallyDrop, ptr::NonNull, str};
use crate::{
Language, LookaheadIterator, Node, ParseState, Parser, Query, QueryCursor, QueryCursorState,
QueryError, Tree, TreeCursor,
};
impl Language {
#[must_use]
pub const unsafe fn from_raw(ptr: *const TSLanguage) -> Self {
Self(ptr)
}
#[must_use]
pub fn into_raw(self) -> *const TSLanguage {
ManuallyDrop::new(self).0
}
}
impl Parser {
#[must_use]
pub const unsafe fn from_raw(ptr: *mut TSParser) -> Self {
Self(NonNull::new_unchecked(ptr))
}
#[must_use]
pub fn into_raw(self) -> *mut TSParser {
ManuallyDrop::new(self).0.as_ptr()
}
}
impl ParseState {
#[must_use]
pub const unsafe fn from_raw(ptr: *mut TSParseState) -> Self {
Self(NonNull::new_unchecked(ptr))
}
#[must_use]
pub fn into_raw(self) -> *mut TSParseState {
ManuallyDrop::new(self).0.as_ptr()
}
}
impl Tree {
#[must_use]
pub const unsafe fn from_raw(ptr: *mut TSTree) -> Self {
Self(NonNull::new_unchecked(ptr))
}
#[must_use]
pub fn into_raw(self) -> *mut TSTree {
ManuallyDrop::new(self).0.as_ptr()
}
}
impl Node<'_> {
#[must_use]
pub const unsafe fn from_raw(raw: TSNode) -> Self {
Self(raw, PhantomData)
}
#[must_use]
pub fn into_raw(self) -> TSNode {
ManuallyDrop::new(self).0
}
}
impl TreeCursor<'_> {
#[must_use]
pub const unsafe fn from_raw(raw: TSTreeCursor) -> Self {
Self(raw, PhantomData)
}
#[must_use]
pub fn into_raw(self) -> TSTreeCursor {
ManuallyDrop::new(self).0
}
}
impl Query {
pub unsafe fn from_raw(ptr: *mut TSQuery, source: &str) -> Result<Self, QueryError> {
Self::from_raw_parts(ptr, source)
}
#[must_use]
pub fn into_raw(self) -> *mut TSQuery {
ManuallyDrop::new(self).ptr.as_ptr()
}
}
impl QueryCursor {
#[must_use]
pub const unsafe fn from_raw(ptr: *mut TSQueryCursor) -> Self {
Self {
ptr: NonNull::new_unchecked(ptr),
}
}
#[must_use]
pub fn into_raw(self) -> *mut TSQueryCursor {
ManuallyDrop::new(self).ptr.as_ptr()
}
}
impl QueryCursorState {
#[must_use]
pub const unsafe fn from_raw(ptr: *mut TSQueryCursorState) -> Self {
Self(NonNull::new_unchecked(ptr))
}
#[must_use]
pub fn into_raw(self) -> *mut TSQueryCursorState {
ManuallyDrop::new(self).0.as_ptr()
}
}
impl LookaheadIterator {
#[must_use]
pub const unsafe fn from_raw(ptr: *mut TSLookaheadIterator) -> Self {
Self(NonNull::new_unchecked(ptr))
}
#[must_use]
pub fn into_raw(self) -> *mut TSLookaheadIterator {
ManuallyDrop::new(self).0.as_ptr()
}
}