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::{ffi,Node,Object};
use glib::{translate::*};

glib::wrapper! {
    #[derive(Debug, PartialOrd, Ord)]
    pub struct Array(Shared<ffi::JsonArray>);

    match fn {
        ref => |ptr| ffi::json_array_ref(ptr),
        unref => |ptr| ffi::json_array_unref(ptr),
        type_ => || ffi::json_array_get_type(),
    }
}

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

    #[doc(alias = "json_array_sized_new")]
    pub fn sized_new(n_elements: u32) -> Array {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::json_array_sized_new(n_elements))
        }
    }

    #[doc(alias = "json_array_add_array_element")]
    pub fn add_array_element(&self, value: Option<Array>) {
        unsafe {
            ffi::json_array_add_array_element(self.to_glib_none().0, value.into_glib_ptr());
        }
    }

    #[doc(alias = "json_array_add_boolean_element")]
    pub fn add_boolean_element(&self, value: bool) {
        unsafe {
            ffi::json_array_add_boolean_element(self.to_glib_none().0, value.into_glib());
        }
    }

    #[doc(alias = "json_array_add_double_element")]
    pub fn add_double_element(&self, value: f64) {
        unsafe {
            ffi::json_array_add_double_element(self.to_glib_none().0, value);
        }
    }

    #[doc(alias = "json_array_add_element")]
    pub fn add_element(&self, node: Node) {
        unsafe {
            ffi::json_array_add_element(self.to_glib_none().0, node.into_glib_ptr());
        }
    }

    #[doc(alias = "json_array_add_int_element")]
    pub fn add_int_element(&self, value: i64) {
        unsafe {
            ffi::json_array_add_int_element(self.to_glib_none().0, value);
        }
    }

    #[doc(alias = "json_array_add_null_element")]
    pub fn add_null_element(&self) {
        unsafe {
            ffi::json_array_add_null_element(self.to_glib_none().0);
        }
    }

    #[doc(alias = "json_array_add_object_element")]
    pub fn add_object_element(&self, value: Option<Object>) {
        unsafe {
            ffi::json_array_add_object_element(self.to_glib_none().0, value.into_glib_ptr());
        }
    }

    #[doc(alias = "json_array_add_string_element")]
    pub fn add_string_element(&self, value: &str) {
        unsafe {
            ffi::json_array_add_string_element(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    #[doc(alias = "json_array_dup_element")]
    pub fn dup_element(&self, index_: u32) -> Node {
        unsafe {
            from_glib_full(ffi::json_array_dup_element(self.to_glib_none().0, index_))
        }
    }

    #[cfg(feature = "v1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
    #[doc(alias = "json_array_equal")]
     fn equal(&self, b: &Array) -> bool {
        unsafe {
            from_glib(ffi::json_array_equal(ToGlibPtr::<*mut ffi::JsonArray>::to_glib_none(self).0 as glib::ffi::gconstpointer, ToGlibPtr::<*mut ffi::JsonArray>::to_glib_none(b).0 as glib::ffi::gconstpointer))
        }
    }

    #[doc(alias = "json_array_foreach_element")]
    pub fn foreach_element<P: FnMut(&Array, u32, &Node)>(&self, func: P) {
        let mut func_data: P = func;
        unsafe extern "C" fn func_func<P: FnMut(&Array, u32, &Node)>(array: *mut ffi::JsonArray, index_: std::ffi::c_uint, element_node: *mut ffi::JsonNode, user_data: glib::ffi::gpointer) {
            let array = from_glib_borrow(array);
            let element_node = from_glib_borrow(element_node);
            let callback = user_data as *mut P;
            (*callback)(&array, index_, &element_node)
        }
        let func = Some(func_func::<P> as _);
        let super_callback0: &mut P = &mut func_data;
        unsafe {
            ffi::json_array_foreach_element(self.to_glib_none().0, func, super_callback0 as *mut _ as *mut _);
        }
    }

    #[doc(alias = "json_array_get_array_element")]
    #[doc(alias = "get_array_element")]
#[must_use]
    pub fn array_element(&self, index_: u32) -> Array {
        unsafe {
            from_glib_none(ffi::json_array_get_array_element(self.to_glib_none().0, index_))
        }
    }

    #[doc(alias = "json_array_get_boolean_element")]
    #[doc(alias = "get_boolean_element")]
    pub fn is_boolean_element(&self, index_: u32) -> bool {
        unsafe {
            from_glib(ffi::json_array_get_boolean_element(self.to_glib_none().0, index_))
        }
    }

    #[doc(alias = "json_array_get_double_element")]
    #[doc(alias = "get_double_element")]
    pub fn double_element(&self, index_: u32) -> f64 {
        unsafe {
            ffi::json_array_get_double_element(self.to_glib_none().0, index_)
        }
    }

    #[doc(alias = "json_array_get_element")]
    #[doc(alias = "get_element")]
    pub fn element(&self, index_: u32) -> Node {
        unsafe {
            from_glib_none(ffi::json_array_get_element(self.to_glib_none().0, index_))
        }
    }

    #[doc(alias = "json_array_get_elements")]
    #[doc(alias = "get_elements")]
    pub fn elements(&self) -> Vec<Node> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::json_array_get_elements(self.to_glib_none().0))
        }
    }

    #[doc(alias = "json_array_get_int_element")]
    #[doc(alias = "get_int_element")]
    pub fn int_element(&self, index_: u32) -> i64 {
        unsafe {
            ffi::json_array_get_int_element(self.to_glib_none().0, index_)
        }
    }

    #[doc(alias = "json_array_get_length")]
    #[doc(alias = "get_length")]
    pub fn length(&self) -> u32 {
        unsafe {
            ffi::json_array_get_length(self.to_glib_none().0)
        }
    }

    #[doc(alias = "json_array_get_null_element")]
    #[doc(alias = "get_null_element")]
    pub fn is_null_element(&self, index_: u32) -> bool {
        unsafe {
            from_glib(ffi::json_array_get_null_element(self.to_glib_none().0, index_))
        }
    }

    #[doc(alias = "json_array_get_object_element")]
    #[doc(alias = "get_object_element")]
    pub fn object_element(&self, index_: u32) -> Object {
        unsafe {
            from_glib_none(ffi::json_array_get_object_element(self.to_glib_none().0, index_))
        }
    }

    #[doc(alias = "json_array_get_string_element")]
    #[doc(alias = "get_string_element")]
    pub fn string_element(&self, index_: u32) -> glib::GString {
        unsafe {
            from_glib_none(ffi::json_array_get_string_element(self.to_glib_none().0, index_))
        }
    }

    #[cfg(feature = "v1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
    #[doc(alias = "json_array_hash")]
     fn hash(&self) -> u32 {
        unsafe {
            ffi::json_array_hash(ToGlibPtr::<*mut ffi::JsonArray>::to_glib_none(self).0 as glib::ffi::gconstpointer)
        }
    }

    #[cfg(feature = "v1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
    #[doc(alias = "json_array_is_immutable")]
    pub fn is_immutable(&self) -> bool {
        unsafe {
            from_glib(ffi::json_array_is_immutable(self.to_glib_none().0))
        }
    }

    #[doc(alias = "json_array_remove_element")]
    pub fn remove_element(&self, index_: u32) {
        unsafe {
            ffi::json_array_remove_element(self.to_glib_none().0, index_);
        }
    }

    #[cfg(feature = "v1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
    #[doc(alias = "json_array_seal")]
    pub fn seal(&self) {
        unsafe {
            ffi::json_array_seal(self.to_glib_none().0);
        }
    }
}

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

#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
impl PartialEq for Array {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]

impl Eq for Array {}

#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
impl std::hash::Hash for Array {
    #[inline]
    fn hash<H>(&self, state: &mut H) where H: std::hash::Hasher {
        std::hash::Hash::hash(&self.hash(), state)
    }
}