Skip to main content

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::{Type, translate::*};
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        unsafe {
28            debug_assert!(!ptr.is_null());
29            IOExtension(ptr::NonNull::new_unchecked(ptr))
30        }
31    }
32}
33
34impl<'a> ToGlibPtr<'a, *mut ffi::GIOExtension> for &'a IOExtension {
35    type Storage = PhantomData<&'a IOExtension>;
36
37    #[inline]
38    fn to_glib_none(&self) -> Stash<'a, *mut ffi::GIOExtension, &'a IOExtension> {
39        Stash(self.0.as_ptr() as *mut ffi::GIOExtension, PhantomData)
40    }
41}
42
43impl IOExtension {
44    #[doc(alias = "g_io_extension_get_name")]
45    pub fn name(&self) -> glib::GString {
46        unsafe { from_glib_none(ffi::g_io_extension_get_name(self.0.as_ptr())) }
47    }
48
49    #[doc(alias = "g_io_extension_get_priority")]
50    pub fn priority(&self) -> i32 {
51        unsafe { ffi::g_io_extension_get_priority(self.0.as_ptr()) }
52    }
53
54    #[doc(alias = "g_io_extension_get_type")]
55    pub fn type_(&self) -> Type {
56        unsafe { from_glib(ffi::g_io_extension_get_type(self.0.as_ptr())) }
57    }
58}