gdk4/
content_provider.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, prelude::*, ContentProvider};
6
7mod sealed {
8    pub trait Sealed {}
9    impl<T: super::IsA<super::ContentProvider>> Sealed for T {}
10}
11
12// rustdoc-stripper-ignore-next
13/// Trait containing manually implemented methods of
14/// [`ContentProvider`](crate::ContentProvider).
15pub trait ContentProviderExtManual: sealed::Sealed + IsA<ContentProvider> {
16    /// Gets the contents of @self stored in @value.
17    ///
18    /// The @value will have been initialized to the `GType` the value should be
19    /// provided in. This given `GType` does not need to be listed in the formats
20    /// returned by [`ContentProviderExt::formats()`][crate::prelude::ContentProviderExt::formats()]. However, if the
21    /// given `GType` is not supported, this operation can fail and
22    /// `G_IO_ERROR_NOT_SUPPORTED` will be reported.
23    ///
24    /// # Returns
25    ///
26    /// [`true`] if the value was set successfully. Otherwise
27    ///   @error will be set to describe the failure.
28    ///
29    /// ## `value`
30    /// the `GValue` to fill
31    #[doc(alias = "gdk_content_provider_get_value")]
32    fn value(&self, type_: glib::Type) -> Result<glib::Value, glib::Error> {
33        unsafe {
34            let mut error = std::ptr::null_mut();
35            let mut value = glib::Value::from_type(type_);
36            let _ = ffi::gdk_content_provider_get_value(
37                self.as_ref().to_glib_none().0,
38                value.to_glib_none_mut().0,
39                &mut error,
40            );
41            if error.is_null() {
42                Ok(value)
43            } else {
44                Err(from_glib_full(error))
45            }
46        }
47    }
48}
49
50impl<O: IsA<ContentProvider>> ContentProviderExtManual for O {}