json_glib/auto/
functions.rs1use crate::{Node, NodeType, ffi};
7use glib::{prelude::*, translate::*};
8
9#[doc(alias = "json_boxed_can_deserialize")]
10pub fn boxed_can_deserialize(gboxed_type: glib::types::Type, node_type: NodeType) -> bool {
11 assert_initialized_main_thread!();
12 unsafe {
13 from_glib(ffi::json_boxed_can_deserialize(
14 gboxed_type.into_glib(),
15 node_type.into_glib(),
16 ))
17 }
18}
19
20#[doc(alias = "json_boxed_can_serialize")]
21pub fn boxed_can_serialize(gboxed_type: glib::types::Type) -> Option<NodeType> {
22 assert_initialized_main_thread!();
23 unsafe {
24 let mut node_type = std::mem::MaybeUninit::uninit();
25 let ret = from_glib(ffi::json_boxed_can_serialize(
26 gboxed_type.into_glib(),
27 node_type.as_mut_ptr(),
28 ));
29 if ret {
30 Some(from_glib(node_type.assume_init()))
31 } else {
32 None
33 }
34 }
35}
36
37#[cfg(feature = "v1_2")]
58#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
59#[doc(alias = "json_from_string")]
60pub fn from_string(str: &str) -> Result<Option<Node>, glib::Error> {
61 assert_initialized_main_thread!();
62 unsafe {
63 let mut error = std::ptr::null_mut();
64 let ret = ffi::json_from_string(str.to_glib_none().0, &mut error);
65 if error.is_null() {
66 Ok(from_glib_full(ret))
67 } else {
68 Err(from_glib_full(error))
69 }
70 }
71}
72
73#[doc(alias = "json_gobject_deserialize")]
74pub fn gobject_deserialize(gtype: glib::types::Type, node: &Node) -> glib::Object {
75 assert_initialized_main_thread!();
76 unsafe {
77 from_glib_full(ffi::json_gobject_deserialize(
78 gtype.into_glib(),
79 node.to_glib_none().0,
80 ))
81 }
82}
83
84#[doc(alias = "json_gobject_from_data")]
85pub fn gobject_from_data(
86 gtype: glib::types::Type,
87 data: &str,
88) -> Result<Option<glib::Object>, glib::Error> {
89 assert_initialized_main_thread!();
90 let length = data.len() as _;
91 unsafe {
92 let mut error = std::ptr::null_mut();
93 let ret = ffi::json_gobject_from_data(
94 gtype.into_glib(),
95 data.to_glib_none().0,
96 length,
97 &mut error,
98 );
99 if error.is_null() {
100 Ok(from_glib_full(ret))
101 } else {
102 Err(from_glib_full(error))
103 }
104 }
105}
106
107#[doc(alias = "json_gobject_serialize")]
108pub fn gobject_serialize(gobject: &impl IsA<glib::Object>) -> Node {
109 assert_initialized_main_thread!();
110 unsafe {
111 from_glib_full(ffi::json_gobject_serialize(
112 gobject.as_ref().to_glib_none().0,
113 ))
114 }
115}
116
117#[doc(alias = "json_gobject_to_data")]
118pub fn gobject_to_data(gobject: &impl IsA<glib::Object>) -> (glib::GString, usize) {
119 assert_initialized_main_thread!();
120 unsafe {
121 let mut length = std::mem::MaybeUninit::uninit();
122 let ret = from_glib_full(ffi::json_gobject_to_data(
123 gobject.as_ref().to_glib_none().0,
124 length.as_mut_ptr(),
125 ));
126 (ret, length.assume_init())
127 }
128}
129
130#[doc(alias = "json_gvariant_deserialize")]
131pub fn gvariant_deserialize(
132 json_node: &Node,
133 signature: Option<&str>,
134) -> Result<Option<glib::Variant>, glib::Error> {
135 assert_initialized_main_thread!();
136 unsafe {
137 let mut error = std::ptr::null_mut();
138 let ret = ffi::json_gvariant_deserialize(
139 json_node.to_glib_none().0,
140 signature.to_glib_none().0,
141 &mut error,
142 );
143 if error.is_null() {
144 Ok(from_glib_none(ret))
145 } else {
146 Err(from_glib_full(error))
147 }
148 }
149}
150
151#[doc(alias = "json_gvariant_deserialize_data")]
152pub fn gvariant_deserialize_data(
153 json: &str,
154 signature: Option<&str>,
155) -> Result<Option<glib::Variant>, glib::Error> {
156 assert_initialized_main_thread!();
157 let length = json.len() as _;
158 unsafe {
159 let mut error = std::ptr::null_mut();
160 let ret = ffi::json_gvariant_deserialize_data(
161 json.to_glib_none().0,
162 length,
163 signature.to_glib_none().0,
164 &mut error,
165 );
166 if error.is_null() {
167 Ok(from_glib_none(ret))
168 } else {
169 Err(from_glib_full(error))
170 }
171 }
172}
173
174#[doc(alias = "json_gvariant_serialize")]
175pub fn gvariant_serialize(variant: &glib::Variant) -> Node {
176 assert_initialized_main_thread!();
177 unsafe { from_glib_full(ffi::json_gvariant_serialize(variant.to_glib_none().0)) }
178}
179
180#[doc(alias = "json_gvariant_serialize_data")]
181pub fn gvariant_serialize_data(variant: &glib::Variant) -> (glib::GString, usize) {
182 assert_initialized_main_thread!();
183 unsafe {
184 let mut length = std::mem::MaybeUninit::uninit();
185 let ret = from_glib_full(ffi::json_gvariant_serialize_data(
186 variant.to_glib_none().0,
187 length.as_mut_ptr(),
188 ));
189 (ret, length.assume_init())
190 }
191}
192
193#[cfg(feature = "v1_2")]
194#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
195#[doc(alias = "json_string_compare")]
196pub fn string_compare(a: &str, b: &str) -> i32 {
197 assert_initialized_main_thread!();
198 unsafe {
199 let s1: *mut i8 = a.to_glib_none().0;
200 let s2: *mut i8 = b.to_glib_none().0;
201 ffi::json_string_compare(s1.cast(), s2.cast())
202 }
203}
204
205#[cfg(feature = "v1_2")]
206#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
207#[doc(alias = "json_string_equal")]
208pub fn string_equal(a: &str, b: &str) -> bool {
209 assert_initialized_main_thread!();
210 unsafe {
211 let s1: *mut i8 = a.to_glib_none().0;
212 let s2: *mut i8 = b.to_glib_none().0;
213 from_glib(ffi::json_string_equal(s1.cast(), s2.cast()))
214 }
215}
216
217#[cfg(feature = "v1_2")]
218#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
219#[doc(alias = "json_string_hash")]
220pub fn string_hash(key: &str) -> u32 {
221 assert_initialized_main_thread!();
222 let s: *mut i8 = key.to_glib_none().0;
223 unsafe { ffi::json_string_hash(s.cast()) }
224}
225
226#[cfg(feature = "v1_2")]
227#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
228#[doc(alias = "json_to_string")]
229pub fn to_string(node: &Node, pretty: bool) -> glib::GString {
230 assert_initialized_main_thread!();
231 unsafe {
232 from_glib_full(ffi::json_to_string(
233 node.to_glib_none().0,
234 pretty.into_glib(),
235 ))
236 }
237}