gdk4/
content_serializer.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, ContentSerializer};
6
7impl ContentSerializer {
8    /// Gets the I/O priority for the current operation.
9    ///
10    /// This is the priority that was passed to [`content_serialize_async()`][crate::content_serialize_async()].
11    ///
12    /// # Returns
13    ///
14    /// the I/O priority for the current operation
15    #[doc(alias = "gdk_content_serializer_get_priority")]
16    #[doc(alias = "get_priority")]
17    pub fn priority(&self) -> glib::Priority {
18        unsafe {
19            from_glib(ffi::gdk_content_serializer_get_priority(
20                self.to_glib_none().0,
21            ))
22        }
23    }
24
25    // rustdoc-stripper-ignore-next
26    /// Similar to [`Self::value`] but panics if the value is of a different
27    /// type.
28    #[doc(alias = "gdk_content_serializer_get_value")]
29    #[doc(alias = "get_value")]
30    pub fn value_as<V: for<'b> FromValue<'b> + 'static>(&self) -> V {
31        self.value()
32            .get_owned::<V>()
33            .expect("Failed to get the value")
34    }
35
36    /// Indicate that the serialization has ended with an error.
37    ///
38    /// This function consumes @error.
39    /// ## `error`
40    /// a `GError`
41    #[doc(alias = "gdk_content_serializer_return_error")]
42    pub fn return_error(&self, error: glib::Error) {
43        unsafe {
44            ffi::gdk_content_serializer_return_error(
45                self.to_glib_none().0,
46                mut_override(error.into_glib_ptr()),
47            );
48        }
49    }
50}