1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;
use glib::Type;
use std::fmt;
use std::ptr;

// rustdoc-stripper-ignore-next
/// The implementation of an `IOExtensionPoint`.
// rustdoc-stripper-ignore-next-stop
/// [`IOExtension`][crate::IOExtension] is an opaque data structure and can only be accessed
/// using the following functions.
#[doc(alias = "GIOExtension")]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct IOExtension(ptr::NonNull<ffi::GIOExtension>);

impl fmt::Debug for IOExtension {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("IOExtension")
            .field("name", &self.name())
            .field("priority", &self.priority())
            .field("type", &self.type_())
            .finish()
    }
}

impl fmt::Display for IOExtension {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "IOExtension")
    }
}

impl FromGlibPtrNone<*mut ffi::GIOExtension> for IOExtension {
    #[inline]
    unsafe fn from_glib_none(ptr: *mut ffi::GIOExtension) -> Self {
        assert!(!ptr.is_null());
        IOExtension(ptr::NonNull::new_unchecked(ptr))
    }
}

impl<'a> ToGlibPtr<'a, *mut ffi::GIOExtension> for &'a IOExtension {
    type Storage = &'a IOExtension;

    #[inline]
    fn to_glib_none(&self) -> Stash<'a, *mut ffi::GIOExtension, &'a IOExtension> {
        Stash(self.0.as_ptr() as *mut ffi::GIOExtension, *self)
    }
}

impl IOExtension {
    /// Gets the name under which `self` was registered.
    ///
    /// Note that the same type may be registered as extension
    /// for multiple extension points, under different names.
    ///
    /// # Returns
    ///
    /// the name of `self`.
    #[doc(alias = "g_io_extension_get_name")]
    pub fn name(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::g_io_extension_get_name(self.0.as_ptr())) }
    }

    /// Gets the priority with which `self` was registered.
    ///
    /// # Returns
    ///
    /// the priority of `self`
    #[doc(alias = "g_io_extension_get_priority")]
    pub fn priority(&self) -> i32 {
        unsafe { ffi::g_io_extension_get_priority(self.0.as_ptr()) }
    }

    /// Gets the type associated with `self`.
    ///
    /// # Returns
    ///
    /// the type of `self`
    #[doc(alias = "g_io_extension_get_type")]
    pub fn type_(&self) -> Type {
        unsafe { from_glib(ffi::g_io_extension_get_type(self.0.as_ptr())) }
    }
}