1#![allow(dead_code)]
2#![allow(non_upper_case_globals)]
3#![allow(non_camel_case_types)]
4#![allow(clippy::missing_const_for_fn)]
5#![allow(
6 clippy::unreadable_literal,
7 reason = "bindgen writes the ABI version without digit separators"
8)]
9
10#[cfg(feature = "bindgen")]
11include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
12
13#[cfg(not(feature = "bindgen"))]
14include!("./bindings.rs");
15
16#[cfg(unix)]
17#[cfg(feature = "std")]
18unsafe extern "C" {
19 #[link_name = "wb_ts_dup"]
20 pub(crate) fn _ts_dup(fd: std::os::raw::c_int) -> std::os::raw::c_int;
21}
22
23#[cfg(windows)]
24#[cfg(feature = "std")]
25unsafe extern "C" {
26 #[link_name = "wb_ts_dup"]
27 pub(crate) fn _ts_dup(handle: *mut std::os::raw::c_void) -> std::os::raw::c_int;
28}
29
30use core::{marker::PhantomData, mem::ManuallyDrop, ptr::NonNull};
31
32use crate::{Language, Node, ParseState, Parser, Tree, TreeCursor};
33
34impl Language {
35 #[must_use]
41 pub const unsafe fn from_raw(ptr: *const TSLanguage) -> Self {
42 Self(ptr)
43 }
44
45 #[must_use]
47 pub fn into_raw(self) -> *const TSLanguage {
48 ManuallyDrop::new(self).0
49 }
50}
51
52impl Parser {
53 #[must_use]
59 pub const unsafe fn from_raw(ptr: *mut TSParser) -> Self {
60 Self(unsafe { NonNull::new_unchecked(ptr) })
61 }
62
63 #[must_use]
71 pub fn into_raw(self) -> *mut TSParser {
72 ManuallyDrop::new(self).0.as_ptr()
73 }
74}
75
76impl ParseState {
77 #[must_use]
83 pub const unsafe fn from_raw(ptr: *mut TSParseState) -> Self {
84 Self(unsafe { NonNull::new_unchecked(ptr) })
85 }
86
87 #[must_use]
89 pub fn into_raw(self) -> *mut TSParseState {
90 ManuallyDrop::new(self).0.as_ptr()
91 }
92}
93
94impl Tree {
95 #[must_use]
101 pub const unsafe fn from_raw(ptr: *mut TSTree) -> Self {
102 Self(unsafe { NonNull::new_unchecked(ptr) })
103 }
104
105 #[must_use]
107 pub fn into_raw(self) -> *mut TSTree {
108 ManuallyDrop::new(self).0.as_ptr()
109 }
110}
111
112impl Node<'_> {
113 #[must_use]
119 pub const unsafe fn from_raw(raw: TSNode) -> Self {
120 Self(raw, PhantomData)
121 }
122
123 #[must_use]
125 pub fn into_raw(self) -> TSNode {
126 ManuallyDrop::new(self).0
127 }
128}
129
130impl TreeCursor<'_> {
131 #[must_use]
137 pub const unsafe fn from_raw(raw: TSTreeCursor) -> Self {
138 Self(raw, PhantomData)
139 }
140
141 #[must_use]
143 pub fn into_raw(self) -> TSTreeCursor {
144 ManuallyDrop::new(self).0
145 }
146}