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#[doc(alias = "GIOExtension")]
11#[derive(Copy, Clone, Eq, PartialEq)]
12pub struct IOExtension(ptr::NonNull<ffi::GIOExtension>);
13
14impl fmt::Debug for IOExtension {
15    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16        f.debug_struct("IOExtension")
17            .field("name", &self.name())
18            .field("priority", &self.priority())
19            .field("type", &self.type_())
20            .finish()
21    }
22}
23
24impl FromGlibPtrNone<*mut ffi::GIOExtension> for IOExtension {
25    #[inline]
26    unsafe fn from_glib_none(ptr: *mut ffi::GIOExtension) -> Self {
27        debug_assert!(!ptr.is_null());
28        IOExtension(ptr::NonNull::new_unchecked(ptr))
29    }
30}
31
32impl<'a> ToGlibPtr<'a, *mut ffi::GIOExtension> for &'a IOExtension {
33    type Storage = PhantomData<&'a IOExtension>;
34
35    #[inline]
36    fn to_glib_none(&self) -> Stash<'a, *mut ffi::GIOExtension, &'a IOExtension> {
37        Stash(self.0.as_ptr() as *mut ffi::GIOExtension, PhantomData)
38    }
39}
40
41impl IOExtension {
42    #[doc(alias = "g_io_extension_get_name")]
43    pub fn name(&self) -> glib::GString {
44        unsafe { from_glib_none(ffi::g_io_extension_get_name(self.0.as_ptr())) }
45    }
46
47    #[doc(alias = "g_io_extension_get_priority")]
48    pub fn priority(&self) -> i32 {
49        unsafe { ffi::g_io_extension_get_priority(self.0.as_ptr()) }
50    }
51
52    #[doc(alias = "g_io_extension_get_type")]
53    pub fn type_(&self) -> Type {
54        unsafe { from_glib(ffi::g_io_extension_get_type(self.0.as_ptr())) }
55    }
56}