1#![allow(dead_code)]
2#![allow(non_upper_case_globals)]
3#![allow(non_camel_case_types)]
4#![allow(clippy::missing_const_for_fn)]
5
6#[cfg(feature = "bindgen")]
7include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
8
9#[cfg(not(feature = "bindgen"))]
10include!("./bindings.rs");
11
12#[cfg(unix)]
13#[cfg(feature = "std")]
14extern "C" {
15 pub(crate) fn _ts_dup(fd: std::os::raw::c_int) -> std::os::raw::c_int;
16}
17
18#[cfg(windows)]
19extern "C" {
20 pub(crate) fn _ts_dup(handle: *mut std::os::raw::c_void) -> std::os::raw::c_int;
21}
22
23use core::{marker::PhantomData, mem::ManuallyDrop, ptr::NonNull, str};
24
25use crate::{
26 Language, LookaheadIterator, Node, ParseState, Parser, Query, QueryCursor, QueryCursorState,
27 QueryError, Tree, TreeCursor,
28};
29
30impl Language {
31 #[must_use]
37 pub const unsafe fn from_raw(ptr: *const TSLanguage) -> Self {
38 Self(ptr)
39 }
40
41 #[must_use]
43 pub fn into_raw(self) -> *const TSLanguage {
44 ManuallyDrop::new(self).0
45 }
46}
47
48impl Parser {
49 #[must_use]
55 pub const unsafe fn from_raw(ptr: *mut TSParser) -> Self {
56 Self(NonNull::new_unchecked(ptr))
57 }
58
59 #[must_use]
67 pub fn into_raw(self) -> *mut TSParser {
68 ManuallyDrop::new(self).0.as_ptr()
69 }
70}
71
72impl ParseState {
73 #[must_use]
79 pub const unsafe fn from_raw(ptr: *mut TSParseState) -> Self {
80 Self(NonNull::new_unchecked(ptr))
81 }
82
83 #[must_use]
85 pub fn into_raw(self) -> *mut TSParseState {
86 ManuallyDrop::new(self).0.as_ptr()
87 }
88}
89
90impl Tree {
91 #[must_use]
97 pub const unsafe fn from_raw(ptr: *mut TSTree) -> Self {
98 Self(NonNull::new_unchecked(ptr))
99 }
100
101 #[must_use]
103 pub fn into_raw(self) -> *mut TSTree {
104 ManuallyDrop::new(self).0.as_ptr()
105 }
106}
107
108impl Node<'_> {
109 #[must_use]
115 pub const unsafe fn from_raw(raw: TSNode) -> Self {
116 Self(raw, PhantomData)
117 }
118
119 #[must_use]
121 pub fn into_raw(self) -> TSNode {
122 ManuallyDrop::new(self).0
123 }
124}
125
126impl TreeCursor<'_> {
127 #[must_use]
133 pub const unsafe fn from_raw(raw: TSTreeCursor) -> Self {
134 Self(raw, PhantomData)
135 }
136
137 #[must_use]
139 pub fn into_raw(self) -> TSTreeCursor {
140 ManuallyDrop::new(self).0
141 }
142}
143
144impl Query {
145 pub unsafe fn from_raw(ptr: *mut TSQuery, source: &str) -> Result<Self, QueryError> {
151 Self::from_raw_parts(ptr, source)
152 }
153
154 #[must_use]
156 pub fn into_raw(self) -> *mut TSQuery {
157 ManuallyDrop::new(self).ptr.as_ptr()
158 }
159}
160
161impl QueryCursor {
162 #[must_use]
168 pub const unsafe fn from_raw(ptr: *mut TSQueryCursor) -> Self {
169 Self {
170 ptr: NonNull::new_unchecked(ptr),
171 }
172 }
173
174 #[must_use]
176 pub fn into_raw(self) -> *mut TSQueryCursor {
177 ManuallyDrop::new(self).ptr.as_ptr()
178 }
179}
180
181impl QueryCursorState {
182 #[must_use]
188 pub const unsafe fn from_raw(ptr: *mut TSQueryCursorState) -> Self {
189 Self(NonNull::new_unchecked(ptr))
190 }
191
192 #[must_use]
194 pub fn into_raw(self) -> *mut TSQueryCursorState {
195 ManuallyDrop::new(self).0.as_ptr()
196 }
197}
198
199impl LookaheadIterator {
200 #[must_use]
206 pub const unsafe fn from_raw(ptr: *mut TSLookaheadIterator) -> Self {
207 Self(NonNull::new_unchecked(ptr))
208 }
209
210 #[must_use]
212 pub fn into_raw(self) -> *mut TSLookaheadIterator {
213 ManuallyDrop::new(self).0.as_ptr()
214 }
215}