json_glib/auto/
array.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::{ffi,Node,Object};
7use glib::{translate::*};
8
9glib::wrapper! {
10    #[derive(Debug, PartialOrd, Ord)]
11    pub struct Array(Shared<ffi::JsonArray>);
12
13    match fn {
14        ref => |ptr| ffi::json_array_ref(ptr),
15        unref => |ptr| ffi::json_array_unref(ptr),
16        type_ => || ffi::json_array_get_type(),
17    }
18}
19
20impl Array {
21    #[doc(alias = "json_array_new")]
22    pub fn new() -> Array {
23        assert_initialized_main_thread!();
24        unsafe {
25            from_glib_full(ffi::json_array_new())
26        }
27    }
28
29    #[doc(alias = "json_array_sized_new")]
30    pub fn sized_new(n_elements: u32) -> Array {
31        assert_initialized_main_thread!();
32        unsafe {
33            from_glib_full(ffi::json_array_sized_new(n_elements))
34        }
35    }
36
37    #[doc(alias = "json_array_add_array_element")]
38    pub fn add_array_element(&self, value: Option<Array>) {
39        unsafe {
40            ffi::json_array_add_array_element(self.to_glib_none().0, value.into_glib_ptr());
41        }
42    }
43
44    #[doc(alias = "json_array_add_boolean_element")]
45    pub fn add_boolean_element(&self, value: bool) {
46        unsafe {
47            ffi::json_array_add_boolean_element(self.to_glib_none().0, value.into_glib());
48        }
49    }
50
51    #[doc(alias = "json_array_add_double_element")]
52    pub fn add_double_element(&self, value: f64) {
53        unsafe {
54            ffi::json_array_add_double_element(self.to_glib_none().0, value);
55        }
56    }
57
58    #[doc(alias = "json_array_add_element")]
59    pub fn add_element(&self, node: Node) {
60        unsafe {
61            ffi::json_array_add_element(self.to_glib_none().0, node.into_glib_ptr());
62        }
63    }
64
65    #[doc(alias = "json_array_add_int_element")]
66    pub fn add_int_element(&self, value: i64) {
67        unsafe {
68            ffi::json_array_add_int_element(self.to_glib_none().0, value);
69        }
70    }
71
72    #[doc(alias = "json_array_add_null_element")]
73    pub fn add_null_element(&self) {
74        unsafe {
75            ffi::json_array_add_null_element(self.to_glib_none().0);
76        }
77    }
78
79    #[doc(alias = "json_array_add_object_element")]
80    pub fn add_object_element(&self, value: Option<Object>) {
81        unsafe {
82            ffi::json_array_add_object_element(self.to_glib_none().0, value.into_glib_ptr());
83        }
84    }
85
86    #[doc(alias = "json_array_add_string_element")]
87    pub fn add_string_element(&self, value: &str) {
88        unsafe {
89            ffi::json_array_add_string_element(self.to_glib_none().0, value.to_glib_none().0);
90        }
91    }
92
93    #[doc(alias = "json_array_dup_element")]
94    pub fn dup_element(&self, index_: u32) -> Node {
95        unsafe {
96            from_glib_full(ffi::json_array_dup_element(self.to_glib_none().0, index_))
97        }
98    }
99
100    #[cfg(feature = "v1_2")]
101    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
102    #[doc(alias = "json_array_equal")]
103     fn equal(&self, b: &Array) -> bool {
104        unsafe {
105            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))
106        }
107    }
108
109    #[doc(alias = "json_array_foreach_element")]
110    pub fn foreach_element<P: FnMut(&Array, u32, &Node)>(&self, func: P) {
111        let mut func_data: P = func;
112        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) {
113            let array = from_glib_borrow(array);
114            let element_node = from_glib_borrow(element_node);
115            let callback = user_data as *mut P;
116            (*callback)(&array, index_, &element_node)
117        }
118        let func = Some(func_func::<P> as _);
119        let super_callback0: &mut P = &mut func_data;
120        unsafe {
121            ffi::json_array_foreach_element(self.to_glib_none().0, func, super_callback0 as *mut _ as *mut _);
122        }
123    }
124
125    #[doc(alias = "json_array_get_array_element")]
126    #[doc(alias = "get_array_element")]
127#[must_use]
128    pub fn array_element(&self, index_: u32) -> Array {
129        unsafe {
130            from_glib_none(ffi::json_array_get_array_element(self.to_glib_none().0, index_))
131        }
132    }
133
134    #[doc(alias = "json_array_get_boolean_element")]
135    #[doc(alias = "get_boolean_element")]
136    pub fn is_boolean_element(&self, index_: u32) -> bool {
137        unsafe {
138            from_glib(ffi::json_array_get_boolean_element(self.to_glib_none().0, index_))
139        }
140    }
141
142    #[doc(alias = "json_array_get_double_element")]
143    #[doc(alias = "get_double_element")]
144    pub fn double_element(&self, index_: u32) -> f64 {
145        unsafe {
146            ffi::json_array_get_double_element(self.to_glib_none().0, index_)
147        }
148    }
149
150    #[doc(alias = "json_array_get_element")]
151    #[doc(alias = "get_element")]
152    pub fn element(&self, index_: u32) -> Node {
153        unsafe {
154            from_glib_none(ffi::json_array_get_element(self.to_glib_none().0, index_))
155        }
156    }
157
158    #[doc(alias = "json_array_get_elements")]
159    #[doc(alias = "get_elements")]
160    pub fn elements(&self) -> Vec<Node> {
161        unsafe {
162            FromGlibPtrContainer::from_glib_container(ffi::json_array_get_elements(self.to_glib_none().0))
163        }
164    }
165
166    #[doc(alias = "json_array_get_int_element")]
167    #[doc(alias = "get_int_element")]
168    pub fn int_element(&self, index_: u32) -> i64 {
169        unsafe {
170            ffi::json_array_get_int_element(self.to_glib_none().0, index_)
171        }
172    }
173
174    #[doc(alias = "json_array_get_length")]
175    #[doc(alias = "get_length")]
176    pub fn length(&self) -> u32 {
177        unsafe {
178            ffi::json_array_get_length(self.to_glib_none().0)
179        }
180    }
181
182    #[doc(alias = "json_array_get_null_element")]
183    #[doc(alias = "get_null_element")]
184    pub fn is_null_element(&self, index_: u32) -> bool {
185        unsafe {
186            from_glib(ffi::json_array_get_null_element(self.to_glib_none().0, index_))
187        }
188    }
189
190    #[doc(alias = "json_array_get_object_element")]
191    #[doc(alias = "get_object_element")]
192    pub fn object_element(&self, index_: u32) -> Object {
193        unsafe {
194            from_glib_none(ffi::json_array_get_object_element(self.to_glib_none().0, index_))
195        }
196    }
197
198    #[doc(alias = "json_array_get_string_element")]
199    #[doc(alias = "get_string_element")]
200    pub fn string_element(&self, index_: u32) -> glib::GString {
201        unsafe {
202            from_glib_none(ffi::json_array_get_string_element(self.to_glib_none().0, index_))
203        }
204    }
205
206    #[cfg(feature = "v1_2")]
207    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
208    #[doc(alias = "json_array_hash")]
209     fn hash(&self) -> u32 {
210        unsafe {
211            ffi::json_array_hash(ToGlibPtr::<*mut ffi::JsonArray>::to_glib_none(self).0 as glib::ffi::gconstpointer)
212        }
213    }
214
215    #[cfg(feature = "v1_2")]
216    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
217    #[doc(alias = "json_array_is_immutable")]
218    pub fn is_immutable(&self) -> bool {
219        unsafe {
220            from_glib(ffi::json_array_is_immutable(self.to_glib_none().0))
221        }
222    }
223
224    #[doc(alias = "json_array_remove_element")]
225    pub fn remove_element(&self, index_: u32) {
226        unsafe {
227            ffi::json_array_remove_element(self.to_glib_none().0, index_);
228        }
229    }
230
231    #[cfg(feature = "v1_2")]
232    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
233    #[doc(alias = "json_array_seal")]
234    pub fn seal(&self) {
235        unsafe {
236            ffi::json_array_seal(self.to_glib_none().0);
237        }
238    }
239}
240
241impl Default for Array {
242                     fn default() -> Self {
243                         Self::new()
244                     }
245                 }
246
247#[cfg(feature = "v1_2")]
248#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
249impl PartialEq for Array {
250    #[inline]
251    fn eq(&self, other: &Self) -> bool {
252        self.equal(other)
253    }
254}
255#[cfg(feature = "v1_2")]
256#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
257
258impl Eq for Array {}
259
260#[cfg(feature = "v1_2")]
261#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
262impl std::hash::Hash for Array {
263    #[inline]
264    fn hash<H>(&self, state: &mut H) where H: std::hash::Hasher {
265        std::hash::Hash::hash(&self.hash(), state)
266    }
267}