json-glib 0.1.0

Rust bindings for the Glib Json library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir
// from gtk-girs (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{Node, ffi};
use glib::translate::*;

glib::wrapper! {
    #[doc(alias = "JsonPath")]
    pub struct Path(Object<ffi::JsonPath, ffi::JsonPathClass>);

    match fn {
        type_ => || ffi::json_path_get_type(),
    }
}

impl Path {
    #[doc(alias = "json_path_new")]
    pub fn new() -> Path {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::json_path_new()) }
    }

    #[doc(alias = "json_path_compile")]
    pub fn compile(&self, expression: &str) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::json_path_compile(
                self.to_glib_none().0,
                expression.to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "json_path_match")]
    #[doc(alias = "match")]
    pub fn match_(&self, root: &Node) -> Node {
        unsafe {
            from_glib_full(ffi::json_path_match(
                self.to_glib_none().0,
                root.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "json_path_query")]
    pub fn query(expression: &str, root: &Node) -> Result<Node, glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::json_path_query(
                expression.to_glib_none().0,
                root.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}

impl Default for Path {
    fn default() -> Self {
        Self::new()
    }
}