json_glib/auto/parser.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::{Array, Node, Object, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::{boxed::Box as Box_, pin::Pin};
14
15glib::wrapper! {
16 /// `JsonParser` provides an object for parsing a JSON data stream, either
17 /// inside a file or inside a static buffer.
18 ///
19 /// ## Using `JsonParser`
20 ///
21 /// The `JsonParser` API is fairly simple:
22 ///
23 /// **⚠️ The following code is in c ⚠️**
24 ///
25 /// ```c
26 /// gboolean
27 /// parse_json (const char *filename)
28 /// {
29 /// g_autoptr(JsonParser) parser = json_parser_new ();
30 /// g_autoptr(GError) error = NULL
31 ///
32 /// json_parser_load_from_file (parser, filename, &error);
33 /// if (error != NULL)
34 /// {
35 /// g_critical ("Unable to parse '%s': %s", filename, error->message);
36 /// return FALSE;
37 /// }
38 ///
39 /// g_autoptr(JsonNode) root = json_parser_get_root (parser);
40 ///
41 /// // manipulate the object tree from the root node
42 ///
43 /// return TRUE
44 /// }
45 /// ```
46 ///
47 /// By default, the entire process of loading the data and parsing it is
48 /// synchronous; the [`ParserExt::load_from_stream_async()`][crate::prelude::ParserExt::load_from_stream_async()] API will
49 /// load the data asynchronously, but parse it in the main context as the
50 /// signals of the parser must be emitted in the same thread. If you do
51 /// not use signals, and you wish to also parse the JSON data without blocking,
52 /// you should use a `GTask` and the synchronous `JsonParser` API inside the
53 /// task itself.
54 ///
55 /// ## Properties
56 ///
57 ///
58 /// #### `immutable`
59 /// Whether the tree built by the parser should be immutable
60 /// when created.
61 ///
62 /// Making the output immutable on creation avoids the expense
63 /// of traversing it to make it immutable later.
64 ///
65 /// Readable | Writeable | Construct Only
66 ///
67 ///
68 /// #### `strict`
69 /// Whether the parser should be strictly conforming to the
70 /// JSON format, or allow custom extensions like comments.
71 ///
72 /// Readable | Writeable
73 ///
74 /// ## Signals
75 ///
76 ///
77 /// #### `array-element`
78 /// The `::array-element` signal is emitted each time a parser
79 /// has successfully parsed a single element of a JSON array.
80 ///
81 ///
82 ///
83 ///
84 /// #### `array-end`
85 /// The `::array-end` signal is emitted each time a parser
86 /// has successfully parsed an entire JSON array.
87 ///
88 ///
89 ///
90 ///
91 /// #### `array-start`
92 /// The `::array-start` signal is emitted each time a parser
93 /// starts parsing a JSON array.
94 ///
95 ///
96 ///
97 ///
98 /// #### `error`
99 /// The `::error` signal is emitted each time a parser encounters
100 /// an error in a JSON stream.
101 ///
102 ///
103 ///
104 ///
105 /// #### `object-end`
106 /// The `::object-end` signal is emitted each time a parser
107 /// has successfully parsed an entire JSON object.
108 ///
109 ///
110 ///
111 ///
112 /// #### `object-member`
113 /// The `::object-member` signal is emitted each time a parser
114 /// has successfully parsed a single member of a JSON object.
115 ///
116 ///
117 ///
118 ///
119 /// #### `object-start`
120 /// This signal is emitted each time a parser starts parsing a JSON object.
121 ///
122 ///
123 ///
124 ///
125 /// #### `parse-end`
126 /// This signal is emitted when a parser successfully finished parsing a
127 /// JSON data stream.
128 ///
129 ///
130 ///
131 ///
132 /// #### `parse-start`
133 /// This signal is emitted when a parser starts parsing a JSON data stream.
134 ///
135 ///
136 ///
137 /// # Implements
138 ///
139 /// [`ParserExt`][trait@crate::prelude::ParserExt], [`trait@glib::ObjectExt`]
140 #[doc(alias = "JsonParser")]
141 pub struct Parser(Object<ffi::JsonParser, ffi::JsonParserClass>);
142
143 match fn {
144 type_ => || ffi::json_parser_get_type(),
145 }
146}
147
148impl Parser {
149 pub const NONE: Option<&'static Parser> = None;
150
151 /// Creates a new JSON parser.
152 ///
153 /// You can use the `JsonParser` to load a JSON stream from either a file or a
154 /// buffer and then walk the hierarchy using the data types API.
155 ///
156 /// # Returns
157 ///
158 /// the newly created parser
159 #[doc(alias = "json_parser_new")]
160 pub fn new() -> Parser {
161 assert_initialized_main_thread!();
162 unsafe { from_glib_full(ffi::json_parser_new()) }
163 }
164
165 /// Creates a new parser instance with its [`immutable`][struct@crate::Parser#immutable]
166 /// property set to `TRUE` to create immutable output trees.
167 ///
168 /// # Returns
169 ///
170 /// the newly created parser
171 #[cfg(feature = "v1_2")]
172 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
173 #[doc(alias = "json_parser_new_immutable")]
174 pub fn new_immutable() -> Parser {
175 assert_initialized_main_thread!();
176 unsafe { from_glib_full(ffi::json_parser_new_immutable()) }
177 }
178
179 // rustdoc-stripper-ignore-next
180 /// Creates a new builder-pattern struct instance to construct [`Parser`] objects.
181 ///
182 /// This method returns an instance of [`ParserBuilder`](crate::builders::ParserBuilder) which can be used to create [`Parser`] objects.
183 pub fn builder() -> ParserBuilder {
184 ParserBuilder::new()
185 }
186}
187
188impl Default for Parser {
189 fn default() -> Self {
190 Self::new()
191 }
192}
193
194// rustdoc-stripper-ignore-next
195/// A [builder-pattern] type to construct [`Parser`] objects.
196///
197/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
198#[must_use = "The builder must be built to be used"]
199pub struct ParserBuilder {
200 builder: glib::object::ObjectBuilder<'static, Parser>,
201}
202
203impl ParserBuilder {
204 fn new() -> Self {
205 Self {
206 builder: glib::object::Object::builder(),
207 }
208 }
209
210 /// Whether the tree built by the parser should be immutable
211 /// when created.
212 ///
213 /// Making the output immutable on creation avoids the expense
214 /// of traversing it to make it immutable later.
215 #[cfg(feature = "v1_2")]
216 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
217 pub fn immutable(self, immutable: bool) -> Self {
218 Self {
219 builder: self.builder.property("immutable", immutable),
220 }
221 }
222
223 /// Whether the parser should be strictly conforming to the
224 /// JSON format, or allow custom extensions like comments.
225 #[cfg(feature = "v1_10")]
226 #[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
227 pub fn strict(self, strict: bool) -> Self {
228 Self {
229 builder: self.builder.property("strict", strict),
230 }
231 }
232
233 // rustdoc-stripper-ignore-next
234 /// Build the [`Parser`].
235 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
236 pub fn build(self) -> Parser {
237 assert_initialized_main_thread!();
238 self.builder.build()
239 }
240}
241
242/// Trait containing all [`struct@Parser`] methods.
243///
244/// # Implementors
245///
246/// [`Parser`][struct@crate::Parser]
247pub trait ParserExt: IsA<Parser> + 'static {
248 /// Retrieves the line currently parsed, starting from 1.
249 ///
250 /// This function has defined behaviour only while parsing; calling this
251 /// function from outside the signal handlers emitted by the parser will
252 /// yield 0.
253 ///
254 /// # Returns
255 ///
256 /// the currently parsed line, or 0.
257 #[doc(alias = "json_parser_get_current_line")]
258 #[doc(alias = "get_current_line")]
259 fn current_line(&self) -> u32 {
260 unsafe { ffi::json_parser_get_current_line(self.as_ref().to_glib_none().0) }
261 }
262
263 /// Retrieves the current position inside the current line, starting
264 /// from 0.
265 ///
266 /// This function has defined behaviour only while parsing; calling this
267 /// function from outside the signal handlers emitted by the parser will
268 /// yield 0.
269 ///
270 /// # Returns
271 ///
272 /// the position in the current line, or 0.
273 #[doc(alias = "json_parser_get_current_pos")]
274 #[doc(alias = "get_current_pos")]
275 fn current_pos(&self) -> u32 {
276 unsafe { ffi::json_parser_get_current_pos(self.as_ref().to_glib_none().0) }
277 }
278
279 /// Retrieves the top level node from the parsed JSON stream.
280 ///
281 /// If the parser input was an empty string, or if parsing failed, the root
282 /// will be `NULL`. It will also be `NULL` if it has been stolen using
283 /// [`steal_root()`][Self::steal_root()].
284 ///
285 /// # Returns
286 ///
287 /// the root node.
288 #[doc(alias = "json_parser_get_root")]
289 #[doc(alias = "get_root")]
290 fn root(&self) -> Option<Node> {
291 unsafe { from_glib_none(ffi::json_parser_get_root(self.as_ref().to_glib_none().0)) }
292 }
293
294 /// Retrieves whether the parser is operating in strict mode.
295 ///
296 /// # Returns
297 ///
298 /// true if the parser is strict, and false otherwise
299 #[cfg(feature = "v1_10")]
300 #[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
301 #[doc(alias = "json_parser_get_strict")]
302 #[doc(alias = "get_strict")]
303 #[doc(alias = "strict")]
304 fn is_strict(&self) -> bool {
305 unsafe { from_glib(ffi::json_parser_get_strict(self.as_ref().to_glib_none().0)) }
306 }
307
308 /// A JSON data stream might sometimes contain an assignment, like:
309 ///
310 /// ```text
311 /// var _json_data = { "member_name" : [ ...
312 /// ```
313 ///
314 /// even though it would technically constitute a violation of the RFC.
315 ///
316 /// `JsonParser` will ignore the left hand identifier and parse the right
317 /// hand value of the assignment. `JsonParser` will record, though, the
318 /// existence of the assignment in the data stream and the variable name
319 /// used.
320 ///
321 /// # Returns
322 ///
323 /// `TRUE` if there was an assignment, and `FALSE` otherwise
324 ///
325 /// ## `variable_name`
326 /// the variable name
327 #[doc(alias = "json_parser_has_assignment")]
328 fn has_assignment(&self) -> Option<glib::GString> {
329 unsafe {
330 let variable_name = std::ptr::null_mut();
331 let ret = from_glib(ffi::json_parser_has_assignment(
332 self.as_ref().to_glib_none().0,
333 variable_name,
334 ));
335 if ret {
336 Some(from_glib_none(*variable_name))
337 } else {
338 None
339 }
340 }
341 }
342
343 /// Loads a JSON stream from a buffer and parses it.
344 ///
345 /// You can call this function multiple times with the same parser, but the
346 /// contents of the parser will be destroyed each time.
347 /// ## `data`
348 /// the buffer to parse
349 /// ## `length`
350 /// the length of the buffer, or -1 if it is `NUL` terminated
351 ///
352 /// # Returns
353 ///
354 /// `TRUE` if the buffer was succesfully parsed
355 #[doc(alias = "json_parser_load_from_data")]
356 fn load_from_data(&self, data: &str) -> Result<(), glib::Error> {
357 let length = data.len() as _;
358 unsafe {
359 let mut error = std::ptr::null_mut();
360 let is_ok = ffi::json_parser_load_from_data(
361 self.as_ref().to_glib_none().0,
362 data.to_glib_none().0,
363 length,
364 &mut error,
365 );
366 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
367 if error.is_null() {
368 Ok(())
369 } else {
370 Err(from_glib_full(error))
371 }
372 }
373 }
374
375 /// Loads a JSON stream from the content of `filename` and parses it.
376 ///
377 /// If the file is large or shared between processes,
378 /// [`load_from_mapped_file()`][Self::load_from_mapped_file()] may be a more efficient
379 /// way to load it.
380 ///
381 /// See also: [`load_from_data()`][Self::load_from_data()]
382 /// ## `filename`
383 /// the path for the file to parse
384 ///
385 /// # Returns
386 ///
387 /// `TRUE` if the file was successfully loaded and parsed.
388 #[doc(alias = "json_parser_load_from_file")]
389 fn load_from_file(&self, filename: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
390 unsafe {
391 let mut error = std::ptr::null_mut();
392 let is_ok = ffi::json_parser_load_from_file(
393 self.as_ref().to_glib_none().0,
394 filename.as_ref().to_glib_none().0,
395 &mut error,
396 );
397 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
398 if error.is_null() {
399 Ok(())
400 } else {
401 Err(from_glib_full(error))
402 }
403 }
404 }
405
406 /// Loads a JSON stream from the content of `filename` and parses it.
407 ///
408 /// Unlike [`load_from_file()`][Self::load_from_file()], `filename` will be memory
409 /// mapped as read-only and parsed. `filename` will be unmapped before this
410 /// function returns.
411 ///
412 /// If mapping or reading the file fails, a `G_FILE_ERROR` will be returned.
413 /// ## `filename`
414 /// the path for the file to parse
415 ///
416 /// # Returns
417 ///
418 /// `TRUE` if the file was successfully loaded and parsed.
419 #[cfg(feature = "v1_6")]
420 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
421 #[doc(alias = "json_parser_load_from_mapped_file")]
422 fn load_from_mapped_file(
423 &self,
424 filename: impl AsRef<std::path::Path>,
425 ) -> Result<(), glib::Error> {
426 unsafe {
427 let mut error = std::ptr::null_mut();
428 let is_ok = ffi::json_parser_load_from_mapped_file(
429 self.as_ref().to_glib_none().0,
430 filename.as_ref().to_glib_none().0,
431 &mut error,
432 );
433 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
434 if error.is_null() {
435 Ok(())
436 } else {
437 Err(from_glib_full(error))
438 }
439 }
440 }
441
442 /// Loads the contents of an input stream and parses them.
443 ///
444 /// If `cancellable` is not `NULL`, then the operation can be cancelled by
445 /// triggering the cancellable object from another thread. If the
446 /// operation was cancelled, `G_IO_ERROR_CANCELLED` will be set
447 /// on the given `error`.
448 /// ## `stream`
449 /// the input stream with the JSON data
450 /// ## `cancellable`
451 /// a #GCancellable
452 ///
453 /// # Returns
454 ///
455 /// `TRUE` if the data stream was successfully read and
456 /// parsed, and `FALSE` otherwise
457 #[doc(alias = "json_parser_load_from_stream")]
458 fn load_from_stream(
459 &self,
460 stream: &impl IsA<gio::InputStream>,
461 cancellable: Option<&impl IsA<gio::Cancellable>>,
462 ) -> Result<(), glib::Error> {
463 unsafe {
464 let mut error = std::ptr::null_mut();
465 let is_ok = ffi::json_parser_load_from_stream(
466 self.as_ref().to_glib_none().0,
467 stream.as_ref().to_glib_none().0,
468 cancellable.map(|p| p.as_ref()).to_glib_none().0,
469 &mut error,
470 );
471 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
472 if error.is_null() {
473 Ok(())
474 } else {
475 Err(from_glib_full(error))
476 }
477 }
478 }
479
480 /// Asynchronously reads the contents of a stream.
481 ///
482 /// For more details, see [`load_from_stream()`][Self::load_from_stream()], which is the
483 /// synchronous version of this call.
484 ///
485 /// When the operation is finished, @callback will be called. You should
486 /// then call `Json::Parser::load_from_stream_finish()` to get the result
487 /// of the operation.
488 /// ## `stream`
489 /// the input stream with the JSON data
490 /// ## `cancellable`
491 /// a #GCancellable
492 /// ## `callback`
493 /// the function to call when the request is satisfied
494 #[doc(alias = "json_parser_load_from_stream_async")]
495 fn load_from_stream_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
496 &self,
497 stream: &impl IsA<gio::InputStream>,
498 cancellable: Option<&impl IsA<gio::Cancellable>>,
499 callback: P,
500 ) {
501 let main_context = glib::MainContext::ref_thread_default();
502 let is_main_context_owner = main_context.is_owner();
503 let has_acquired_main_context = (!is_main_context_owner)
504 .then(|| main_context.acquire().ok())
505 .flatten();
506 assert!(
507 is_main_context_owner || has_acquired_main_context.is_some(),
508 "Async operations only allowed if the thread is owning the MainContext"
509 );
510
511 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
512 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
513 unsafe extern "C" fn load_from_stream_async_trampoline<
514 P: FnOnce(Result<(), glib::Error>) + 'static,
515 >(
516 _source_object: *mut glib::gobject_ffi::GObject,
517 res: *mut gio::ffi::GAsyncResult,
518 user_data: glib::ffi::gpointer,
519 ) {
520 let mut error = std::ptr::null_mut();
521 ffi::json_parser_load_from_stream_finish(_source_object as *mut _, res, &mut error);
522 let result = if error.is_null() {
523 Ok(())
524 } else {
525 Err(from_glib_full(error))
526 };
527 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
528 Box_::from_raw(user_data as *mut _);
529 let callback: P = callback.into_inner();
530 callback(result);
531 }
532 let callback = load_from_stream_async_trampoline::<P>;
533 unsafe {
534 ffi::json_parser_load_from_stream_async(
535 self.as_ref().to_glib_none().0,
536 stream.as_ref().to_glib_none().0,
537 cancellable.map(|p| p.as_ref()).to_glib_none().0,
538 Some(callback),
539 Box_::into_raw(user_data) as *mut _,
540 );
541 }
542 }
543
544 fn load_from_stream_future(
545 &self,
546 stream: &(impl IsA<gio::InputStream> + Clone + 'static),
547 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
548 let stream = stream.clone();
549 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
550 obj.load_from_stream_async(&stream, Some(cancellable), move |res| {
551 send.resolve(res);
552 });
553 }))
554 }
555
556 /// Sets whether the parser should operate in strict mode.
557 ///
558 /// If @strict is true, `JsonParser` will strictly conform to
559 /// the JSON format.
560 ///
561 /// If @strict is false, `JsonParser` will allow custom extensions
562 /// to the JSON format, like comments.
563 /// ## `strict`
564 /// whether the parser should be strict
565 #[cfg(feature = "v1_10")]
566 #[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
567 #[doc(alias = "json_parser_set_strict")]
568 #[doc(alias = "strict")]
569 fn set_strict(&self, strict: bool) {
570 unsafe {
571 ffi::json_parser_set_strict(self.as_ref().to_glib_none().0, strict.into_glib());
572 }
573 }
574
575 /// Steals the top level node from the parsed JSON stream.
576 ///
577 /// This will be `NULL` in the same situations as [`root()`][Self::root()]
578 /// return `NULL`.
579 ///
580 /// # Returns
581 ///
582 /// the root node
583 #[cfg(feature = "v1_4")]
584 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
585 #[doc(alias = "json_parser_steal_root")]
586 fn steal_root(&self) -> Option<Node> {
587 unsafe { from_glib_full(ffi::json_parser_steal_root(self.as_ref().to_glib_none().0)) }
588 }
589
590 /// Whether the tree built by the parser should be immutable
591 /// when created.
592 ///
593 /// Making the output immutable on creation avoids the expense
594 /// of traversing it to make it immutable later.
595 #[cfg(feature = "v1_2")]
596 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
597 fn is_immutable(&self) -> bool {
598 ObjectExt::property(self.as_ref(), "immutable")
599 }
600
601 /// The `::array-element` signal is emitted each time a parser
602 /// has successfully parsed a single element of a JSON array.
603 ///
604 /// # Deprecated since 1.10
605 ///
606 /// Derive your own parser type from `JsonParser` and
607 /// override the [`ParserImpl::array_element()`][crate::subclass::prelude::ParserImpl::array_element()] virtual function
608 /// ## `array`
609 /// a JSON array
610 /// ## `index_`
611 /// the index of the newly parsed array element
612 #[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
613 #[doc(alias = "array-element")]
614 fn connect_array_element<F: Fn(&Self, &Array, i32) + 'static>(&self, f: F) -> SignalHandlerId {
615 unsafe extern "C" fn array_element_trampoline<
616 P: IsA<Parser>,
617 F: Fn(&P, &Array, i32) + 'static,
618 >(
619 this: *mut ffi::JsonParser,
620 array: *mut ffi::JsonArray,
621 index_: std::ffi::c_int,
622 f: glib::ffi::gpointer,
623 ) {
624 let f: &F = &*(f as *const F);
625 f(
626 Parser::from_glib_borrow(this).unsafe_cast_ref(),
627 &from_glib_borrow(array),
628 index_,
629 )
630 }
631 unsafe {
632 let f: Box_<F> = Box_::new(f);
633 connect_raw(
634 self.as_ptr() as *mut _,
635 c"array-element".as_ptr() as *const _,
636 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
637 array_element_trampoline::<Self, F> as *const (),
638 )),
639 Box_::into_raw(f),
640 )
641 }
642 }
643
644 /// The `::array-end` signal is emitted each time a parser
645 /// has successfully parsed an entire JSON array.
646 ///
647 /// # Deprecated since 1.10
648 ///
649 /// Derive your own parser type from `JsonParser` and
650 /// override the [`ParserImpl::array_end()`][crate::subclass::prelude::ParserImpl::array_end()] virtual function
651 /// ## `array`
652 /// the parsed JSON array
653 #[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
654 #[doc(alias = "array-end")]
655 fn connect_array_end<F: Fn(&Self, &Array) + 'static>(&self, f: F) -> SignalHandlerId {
656 unsafe extern "C" fn array_end_trampoline<P: IsA<Parser>, F: Fn(&P, &Array) + 'static>(
657 this: *mut ffi::JsonParser,
658 array: *mut ffi::JsonArray,
659 f: glib::ffi::gpointer,
660 ) {
661 let f: &F = &*(f as *const F);
662 f(
663 Parser::from_glib_borrow(this).unsafe_cast_ref(),
664 &from_glib_borrow(array),
665 )
666 }
667 unsafe {
668 let f: Box_<F> = Box_::new(f);
669 connect_raw(
670 self.as_ptr() as *mut _,
671 c"array-end".as_ptr() as *const _,
672 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
673 array_end_trampoline::<Self, F> as *const (),
674 )),
675 Box_::into_raw(f),
676 )
677 }
678 }
679
680 /// The `::array-start` signal is emitted each time a parser
681 /// starts parsing a JSON array.
682 ///
683 /// # Deprecated since 1.10
684 ///
685 /// Derive your own parser type from `JsonParser` and
686 /// override the [`ParserImpl::array_start()`][crate::subclass::prelude::ParserImpl::array_start()] virtual function
687 #[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
688 #[doc(alias = "array-start")]
689 fn connect_array_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
690 unsafe extern "C" fn array_start_trampoline<P: IsA<Parser>, F: Fn(&P) + 'static>(
691 this: *mut ffi::JsonParser,
692 f: glib::ffi::gpointer,
693 ) {
694 let f: &F = &*(f as *const F);
695 f(Parser::from_glib_borrow(this).unsafe_cast_ref())
696 }
697 unsafe {
698 let f: Box_<F> = Box_::new(f);
699 connect_raw(
700 self.as_ptr() as *mut _,
701 c"array-start".as_ptr() as *const _,
702 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
703 array_start_trampoline::<Self, F> as *const (),
704 )),
705 Box_::into_raw(f),
706 )
707 }
708 }
709
710 //#[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
711 //#[doc(alias = "error")]
712 //fn connect_error<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
713 // Unimplemented error: *.Pointer
714 //}
715
716 /// The `::object-end` signal is emitted each time a parser
717 /// has successfully parsed an entire JSON object.
718 ///
719 /// # Deprecated since 1.10
720 ///
721 /// Derive your own parser type from `JsonParser` and
722 /// override the [`ParserImpl::object_end()`][crate::subclass::prelude::ParserImpl::object_end()] virtual function
723 /// ## `object`
724 /// the parsed JSON object
725 #[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
726 #[doc(alias = "object-end")]
727 fn connect_object_end<F: Fn(&Self, &Object) + 'static>(&self, f: F) -> SignalHandlerId {
728 unsafe extern "C" fn object_end_trampoline<P: IsA<Parser>, F: Fn(&P, &Object) + 'static>(
729 this: *mut ffi::JsonParser,
730 object: *mut ffi::JsonObject,
731 f: glib::ffi::gpointer,
732 ) {
733 let f: &F = &*(f as *const F);
734 f(
735 Parser::from_glib_borrow(this).unsafe_cast_ref(),
736 &from_glib_borrow(object),
737 )
738 }
739 unsafe {
740 let f: Box_<F> = Box_::new(f);
741 connect_raw(
742 self.as_ptr() as *mut _,
743 c"object-end".as_ptr() as *const _,
744 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
745 object_end_trampoline::<Self, F> as *const (),
746 )),
747 Box_::into_raw(f),
748 )
749 }
750 }
751
752 /// The `::object-member` signal is emitted each time a parser
753 /// has successfully parsed a single member of a JSON object.
754 ///
755 /// # Deprecated since 1.10
756 ///
757 /// Derive your own parser type from `JsonParser` and
758 /// override the [`ParserImpl::object_member()`][crate::subclass::prelude::ParserImpl::object_member()] virtual function
759 /// ## `object`
760 /// the JSON object being parsed
761 /// ## `member_name`
762 /// the name of the newly parsed member
763 #[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
764 #[doc(alias = "object-member")]
765 fn connect_object_member<F: Fn(&Self, &Object, &str) + 'static>(
766 &self,
767 f: F,
768 ) -> SignalHandlerId {
769 unsafe extern "C" fn object_member_trampoline<
770 P: IsA<Parser>,
771 F: Fn(&P, &Object, &str) + 'static,
772 >(
773 this: *mut ffi::JsonParser,
774 object: *mut ffi::JsonObject,
775 member_name: *mut std::ffi::c_char,
776 f: glib::ffi::gpointer,
777 ) {
778 let f: &F = &*(f as *const F);
779 f(
780 Parser::from_glib_borrow(this).unsafe_cast_ref(),
781 &from_glib_borrow(object),
782 &glib::GString::from_glib_borrow(member_name),
783 )
784 }
785 unsafe {
786 let f: Box_<F> = Box_::new(f);
787 connect_raw(
788 self.as_ptr() as *mut _,
789 c"object-member".as_ptr() as *const _,
790 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
791 object_member_trampoline::<Self, F> as *const (),
792 )),
793 Box_::into_raw(f),
794 )
795 }
796 }
797
798 /// This signal is emitted each time a parser starts parsing a JSON object.
799 ///
800 /// # Deprecated since 1.10
801 ///
802 /// Derive your own parser type from `JsonParser` and
803 /// override the [`ParserImpl::object_start()`][crate::subclass::prelude::ParserImpl::object_start()] virtual function
804 #[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
805 #[doc(alias = "object-start")]
806 fn connect_object_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
807 unsafe extern "C" fn object_start_trampoline<P: IsA<Parser>, F: Fn(&P) + 'static>(
808 this: *mut ffi::JsonParser,
809 f: glib::ffi::gpointer,
810 ) {
811 let f: &F = &*(f as *const F);
812 f(Parser::from_glib_borrow(this).unsafe_cast_ref())
813 }
814 unsafe {
815 let f: Box_<F> = Box_::new(f);
816 connect_raw(
817 self.as_ptr() as *mut _,
818 c"object-start".as_ptr() as *const _,
819 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
820 object_start_trampoline::<Self, F> as *const (),
821 )),
822 Box_::into_raw(f),
823 )
824 }
825 }
826
827 /// This signal is emitted when a parser successfully finished parsing a
828 /// JSON data stream.
829 ///
830 /// # Deprecated since 1.10
831 ///
832 /// Derive your own parser type from `JsonParser` and
833 /// override the [`ParserImpl::parse_end()`][crate::subclass::prelude::ParserImpl::parse_end()] virtual function
834 #[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
835 #[doc(alias = "parse-end")]
836 fn connect_parse_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
837 unsafe extern "C" fn parse_end_trampoline<P: IsA<Parser>, F: Fn(&P) + 'static>(
838 this: *mut ffi::JsonParser,
839 f: glib::ffi::gpointer,
840 ) {
841 let f: &F = &*(f as *const F);
842 f(Parser::from_glib_borrow(this).unsafe_cast_ref())
843 }
844 unsafe {
845 let f: Box_<F> = Box_::new(f);
846 connect_raw(
847 self.as_ptr() as *mut _,
848 c"parse-end".as_ptr() as *const _,
849 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
850 parse_end_trampoline::<Self, F> as *const (),
851 )),
852 Box_::into_raw(f),
853 )
854 }
855 }
856
857 /// This signal is emitted when a parser starts parsing a JSON data stream.
858 ///
859 /// # Deprecated since 1.10
860 ///
861 /// Derive your own parser type from `JsonParser` and
862 /// override the [`ParserImpl::parse_start()`][crate::subclass::prelude::ParserImpl::parse_start()] virtual function
863 #[cfg_attr(feature = "v1_10", deprecated = "Since 1.10")]
864 #[doc(alias = "parse-start")]
865 fn connect_parse_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
866 unsafe extern "C" fn parse_start_trampoline<P: IsA<Parser>, F: Fn(&P) + 'static>(
867 this: *mut ffi::JsonParser,
868 f: glib::ffi::gpointer,
869 ) {
870 let f: &F = &*(f as *const F);
871 f(Parser::from_glib_borrow(this).unsafe_cast_ref())
872 }
873 unsafe {
874 let f: Box_<F> = Box_::new(f);
875 connect_raw(
876 self.as_ptr() as *mut _,
877 c"parse-start".as_ptr() as *const _,
878 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
879 parse_start_trampoline::<Self, F> as *const (),
880 )),
881 Box_::into_raw(f),
882 )
883 }
884 }
885
886 #[cfg(feature = "v1_10")]
887 #[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
888 #[doc(alias = "strict")]
889 fn connect_strict_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
890 unsafe extern "C" fn notify_strict_trampoline<P: IsA<Parser>, F: Fn(&P) + 'static>(
891 this: *mut ffi::JsonParser,
892 _param_spec: glib::ffi::gpointer,
893 f: glib::ffi::gpointer,
894 ) {
895 let f: &F = &*(f as *const F);
896 f(Parser::from_glib_borrow(this).unsafe_cast_ref())
897 }
898 unsafe {
899 let f: Box_<F> = Box_::new(f);
900 connect_raw(
901 self.as_ptr() as *mut _,
902 c"notify::strict".as_ptr() as *const _,
903 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
904 notify_strict_trampoline::<Self, F> as *const (),
905 )),
906 Box_::into_raw(f),
907 )
908 }
909 }
910}
911
912impl<O: IsA<Parser>> ParserExt for O {}