ref(rust_bindings): move into_raw() functions into the ffi module
This commit is contained in:
parent
576e4c7d06
commit
6c2957c8d3
2 changed files with 56 additions and 39 deletions
|
|
@ -7,3 +7,58 @@ include!("./bindings.rs");
|
|||
extern "C" {
|
||||
pub(crate) fn dup(fd: std::os::raw::c_int) -> std::os::raw::c_int;
|
||||
}
|
||||
|
||||
use crate::{Language, Node, Parser, Query, QueryCursor, Tree, TreeCursor};
|
||||
use std::mem::ManuallyDrop;
|
||||
|
||||
impl Language {
|
||||
/// Consumes the [Language], returning a raw pointer to the underlying C structure.
|
||||
pub fn into_raw(self) -> *const TSLanguage {
|
||||
ManuallyDrop::new(self).0
|
||||
}
|
||||
}
|
||||
|
||||
impl Parser {
|
||||
/// Consumes the [Parser], returning a raw pointer to the underlying C structure.
|
||||
pub fn into_raw(mut self) -> *mut TSParser {
|
||||
self.stop_printing_dot_graphs();
|
||||
self.set_logger(None);
|
||||
|
||||
ManuallyDrop::new(self).0.as_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
impl Tree {
|
||||
/// Consumes the [Tree], returning a raw pointer to the underlying C structure.
|
||||
pub fn into_raw(self) -> *mut TSTree {
|
||||
ManuallyDrop::new(self).0.as_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tree> Node<'tree> {
|
||||
/// Consumes the [Node], returning a raw pointer to the underlying C structure.
|
||||
pub fn into_raw(self) -> *mut TSNode {
|
||||
&mut ManuallyDrop::new(self).0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TreeCursor<'a> {
|
||||
/// Consumes the [TreeCursor], returning a raw pointer to the underlying C structure.
|
||||
pub fn into_raw(self) -> *mut TSTreeCursor {
|
||||
&mut ManuallyDrop::new(self).0
|
||||
}
|
||||
}
|
||||
|
||||
impl Query {
|
||||
/// Consumes the [Query], returning a raw pointer to the underlying C structure.
|
||||
pub fn into_raw(self) -> *mut TSQuery {
|
||||
ManuallyDrop::new(self).ptr.as_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
impl QueryCursor {
|
||||
/// Consumes the [QueryCursor], returning a raw pointer to the underlying C structure.
|
||||
pub fn into_raw(self) -> *mut TSQueryCursor {
|
||||
ManuallyDrop::new(self).ptr.as_ptr()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue