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
use crate::pg_sys;
#[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"),
)
}
}
}