json_glib/auto/
path.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir
3// from gtk-girs (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{Node, ffi};
7use glib::translate::*;
8
9glib::wrapper! {
10    #[doc(alias = "JsonPath")]
11    pub struct Path(Object<ffi::JsonPath, ffi::JsonPathClass>);
12
13    match fn {
14        type_ => || ffi::json_path_get_type(),
15    }
16}
17
18impl Path {
19    #[doc(alias = "json_path_new")]
20    pub fn new() -> Path {
21        assert_initialized_main_thread!();
22        unsafe { from_glib_full(ffi::json_path_new()) }
23    }
24
25    #[doc(alias = "json_path_compile")]
26    pub fn compile(&self, expression: &str) -> Result<(), glib::Error> {
27        unsafe {
28            let mut error = std::ptr::null_mut();
29            let is_ok = ffi::json_path_compile(
30                self.to_glib_none().0,
31                expression.to_glib_none().0,
32                &mut error,
33            );
34            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
35            if error.is_null() {
36                Ok(())
37            } else {
38                Err(from_glib_full(error))
39            }
40        }
41    }
42
43    #[doc(alias = "json_path_match")]
44    #[doc(alias = "match")]
45    pub fn match_(&self, root: &Node) -> Node {
46        unsafe {
47            from_glib_full(ffi::json_path_match(
48                self.to_glib_none().0,
49                root.to_glib_none().0,
50            ))
51        }
52    }
53
54    #[doc(alias = "json_path_query")]
55    pub fn query(expression: &str, root: &Node) -> Result<Node, glib::Error> {
56        assert_initialized_main_thread!();
57        unsafe {
58            let mut error = std::ptr::null_mut();
59            let ret = ffi::json_path_query(
60                expression.to_glib_none().0,
61                root.to_glib_none().0,
62                &mut error,
63            );
64            if error.is_null() {
65                Ok(from_glib_full(ret))
66            } else {
67                Err(from_glib_full(error))
68            }
69        }
70    }
71}
72
73impl Default for Path {
74    fn default() -> Self {
75        Self::new()
76    }
77}