simdjson_rust/dom/
document.rs1use std::ptr::NonNull;
2
3use simdjson_sys as ffi;
4
5use super::Element;
6use crate::macros::impl_drop;
7
8pub struct Document {
9 ptr: NonNull<ffi::SJ_DOM_document>,
10}
11
12impl Default for Document {
13 fn default() -> Self {
14 Self {
15 ptr: unsafe { NonNull::new_unchecked(ffi::SJ_DOM_document_new()) },
16 }
17 }
18}
19
20impl Document {
21 pub fn new(ptr: NonNull<ffi::SJ_DOM_document>) -> Self {
22 Self { ptr }
23 }
24
25 pub fn root(&self) -> Element<'_> {
26 Element::new(unsafe {
27 NonNull::new_unchecked(ffi::SJ_DOM_document_root(self.ptr.as_ptr()))
28 })
29 }
30
31 pub fn as_ptr(&self) -> *mut ffi::SJ_DOM_document {
32 self.ptr.as_ptr()
33 }
34}
35
36impl_drop!(Document, ffi::SJ_DOM_document_free);