gdk4/
content_deserializer.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{translate::*, value::FromValue};
4
5use crate::{ffi, ContentDeserializer};
6
7impl ContentDeserializer {
8    pub fn set_value(&self, value: glib::Value) {
9        assert!(value.type_() == self.type_(), "Type mismatch");
10
11        let src_value = value.to_glib_none();
12        unsafe {
13            let dest_value = ffi::gdk_content_deserializer_get_value(self.to_glib_none().0);
14            glib::gobject_ffi::g_value_copy(src_value.0, dest_value);
15        }
16    }
17
18    /// Gets the I/O priority for the current operation.
19    ///
20    /// This is the priority that was passed to [`content_deserialize_async()`][crate::content_deserialize_async()].
21    ///
22    /// # Returns
23    ///
24    /// the I/O priority for the current operation
25    #[doc(alias = "gdk_content_deserializer_get_priority")]
26    #[doc(alias = "get_priority")]
27    pub fn priority(&self) -> glib::Priority {
28        unsafe {
29            from_glib(ffi::gdk_content_deserializer_get_priority(
30                self.to_glib_none().0,
31            ))
32        }
33    }
34
35    // rustdoc-stripper-ignore-next
36    /// Similar to [`Self::value`] but panics if the value is of a different
37    /// type.
38    #[doc(alias = "gdk_content_deserializer_get_value")]
39    #[doc(alias = "get_value")]
40    pub fn value_as<V: for<'b> FromValue<'b> + 'static>(&self) -> V {
41        self.value()
42            .get_owned::<V>()
43            .expect("Failed to get the value")
44    }
45
46    /// Indicate that the deserialization has ended with an error.
47    ///
48    /// This function consumes @error.
49    /// ## `error`
50    /// a `GError`
51    #[doc(alias = "gdk_content_deserializer_return_error")]
52    pub fn return_error(&self, error: glib::Error) {
53        unsafe {
54            ffi::gdk_content_deserializer_return_error(
55                self.to_glib_none().0,
56                mut_override(error.into_glib_ptr()),
57            );
58        }
59    }
60}