glib/auto/
markup_parse_context.rs1use crate::{ffi, translate::*, Error};
6
7crate::wrapper! {
8 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 pub struct MarkupParseContext(Shared<ffi::GMarkupParseContext>);
10
11 match fn {
12 ref => |ptr| ffi::g_markup_parse_context_ref(ptr),
13 unref => |ptr| ffi::g_markup_parse_context_unref(ptr),
14 type_ => || ffi::g_markup_parse_context_get_type(),
15 }
16}
17
18impl MarkupParseContext {
19 #[doc(alias = "g_markup_parse_context_end_parse")]
25 pub fn end_parse(&self) -> Result<(), crate::Error> {
26 unsafe {
27 let mut error = std::ptr::null_mut();
28 let is_ok = ffi::g_markup_parse_context_end_parse(self.to_glib_none().0, &mut error);
29 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
30 if error.is_null() {
31 Ok(())
32 } else {
33 Err(from_glib_full(error))
34 }
35 }
36 }
37
38 #[doc(alias = "g_markup_parse_context_get_element")]
39 #[doc(alias = "get_element")]
40 pub fn element(&self) -> crate::GString {
41 unsafe {
42 from_glib_none(ffi::g_markup_parse_context_get_element(
43 self.to_glib_none().0,
44 ))
45 }
46 }
47
48 #[doc(alias = "g_markup_parse_context_get_element_stack")]
49 #[doc(alias = "get_element_stack")]
50 pub fn element_stack(&self) -> Vec<crate::GString> {
51 unsafe {
52 FromGlibPtrContainer::from_glib_none(ffi::g_markup_parse_context_get_element_stack(
53 self.to_glib_none().0,
54 ))
55 }
56 }
57
58 #[doc(alias = "g_markup_parse_context_get_position")]
59 #[doc(alias = "get_position")]
60 pub fn position(&self) -> (i32, i32) {
61 unsafe {
62 let mut line_number = std::mem::MaybeUninit::uninit();
63 let mut char_number = std::mem::MaybeUninit::uninit();
64 ffi::g_markup_parse_context_get_position(
65 self.to_glib_none().0,
66 line_number.as_mut_ptr(),
67 char_number.as_mut_ptr(),
68 );
69 (line_number.assume_init(), char_number.assume_init())
70 }
71 }
72
73 #[doc(alias = "g_markup_parse_context_parse")]
74 pub fn parse(&self, text: &str) -> Result<(), crate::Error> {
75 let text_len = text.len() as _;
76 unsafe {
77 let mut error = std::ptr::null_mut();
78 let is_ok = ffi::g_markup_parse_context_parse(
79 self.to_glib_none().0,
80 text.to_glib_none().0,
81 text_len,
82 &mut error,
83 );
84 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
85 if error.is_null() {
86 Ok(())
87 } else {
88 Err(from_glib_full(error))
89 }
90 }
91 }
92
93 }