1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#[cfg(feature = "pg10")]
mod pg10;
#[cfg(feature = "pg11")]
mod pg11;
#[cfg(feature = "pg12")]
mod pg12;
#[cfg(feature = "pg10")]
pub use pg10::*;
#[cfg(feature = "pg11")]
pub use pg11::*;
#[cfg(feature = "pg12")]
pub use pg12::*;
use crate::{pg_sys, PgBox};
#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[inline]
pub fn is_a(nodeptr: *mut pg_sys::Node, tag: pg_sys::NodeTag) -> bool {
!nodeptr.is_null() && unsafe { nodeptr.as_ref().unwrap().type_ == tag }
}
pub fn node_to_string<'a>(nodeptr: *mut pg_sys::Node) -> Option<&'a str> {
if nodeptr.is_null() {
None
} else {
let string = unsafe { pg_sys::nodeToString(nodeptr as crate::void_ptr) };
if string.is_null() {
None
} else {
Some(
unsafe { std::ffi::CStr::from_ptr(string) }
.to_str()
.expect("unable to convert Node into a &str"),
)
}
}
}
impl PgNode {
pub fn is<T>(self, boxed: PgBox<T>) -> bool {
let node = boxed.as_ptr() as *mut pg_sys::Node;
let me = self as u32;
!node.is_null() && unsafe { node.as_ref() }.unwrap().type_ == me
}
}