gio/
io_extension.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{fmt, marker::PhantomData, ptr};
4
5use crate::ffi;
6use glib::{translate::*, Type};
7
8// rustdoc-stripper-ignore-next
9/// The implementation of an `IOExtensionPoint`.
10// rustdoc-stripper-ignore-next-stop
11/// #GIOExtension is an opaque data structure and can only be accessed
12/// using the following functions.
13#[doc(alias = "GIOExtension")]
14#[derive(Copy, Clone, Eq, PartialEq)]
15pub struct IOExtension(ptr::NonNull<ffi::GIOExtension>);
16
17impl fmt::Debug for IOExtension {
18    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19        f.debug_struct("IOExtension")
20            .field("name", &self.name())
21            .field("priority", &self.priority())
22            .field("type", &self.type_())
23            .finish()
24    }
25}
26
27impl FromGlibPtrNone<*mut ffi::GIOExtension> for IOExtension {
28    #[inline]
29    unsafe fn from_glib_none(ptr: *mut ffi::GIOExtension) -> Self {
30        debug_assert!(!ptr.is_null());
31        IOExtension(ptr::NonNull::new_unchecked(ptr))
32    }
33}
34
35impl<'a> ToGlibPtr<'a, *mut ffi::GIOExtension> for &'a IOExtension {
36    type Storage = PhantomData<&'a IOExtension>;
37
38    #[inline]
39    fn to_glib_none(&self) -> Stash<'a, *mut ffi::GIOExtension, &'a IOExtension> {
40        Stash(self.0.as_ptr() as *mut ffi::GIOExtension, PhantomData)
41    }
42}
43
44impl IOExtension {
45    /// Gets the name under which @self was registered.
46    ///
47    /// Note that the same type may be registered as extension
48    /// for multiple extension points, under different names.
49    ///
50    /// # Returns
51    ///
52    /// the name of @self.
53    #[doc(alias = "g_io_extension_get_name")]
54    pub fn name(&self) -> glib::GString {
55        unsafe { from_glib_none(ffi::g_io_extension_get_name(self.0.as_ptr())) }
56    }
57
58    /// Gets the priority with which @self was registered.
59    ///
60    /// # Returns
61    ///
62    /// the priority of @self
63    #[doc(alias = "g_io_extension_get_priority")]
64    pub fn priority(&self) -> i32 {
65        unsafe { ffi::g_io_extension_get_priority(self.0.as_ptr()) }
66    }
67
68    /// Gets the type associated with @self.
69    ///
70    /// # Returns
71    ///
72    /// the type of @self
73    #[doc(alias = "g_io_extension_get_type")]
74    pub fn type_(&self) -> Type {
75        unsafe { from_glib(ffi::g_io_extension_get_type(self.0.as_ptr())) }
76    }
77}