polkit_rs/auto/
unix_group.rs

1// Generated by gir (https://github.com/gtk-rs/gir @ b2a1c6f9b362)
2// from ../misc (@ ???)
3// DO NOT EDIT
4
5use crate::{Identity, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "PolkitUnixGroup")]
15    pub struct UnixGroup(Object<ffi::PolkitUnixGroup, ffi::PolkitUnixGroupClass>) @implements Identity;
16
17    match fn {
18        type_ => || ffi::polkit_unix_group_get_type(),
19    }
20}
21
22impl UnixGroup {
23    #[doc(alias = "polkit_unix_group_get_gid")]
24    #[doc(alias = "get_gid")]
25    pub fn gid(&self) -> i32 {
26        unsafe { ffi::polkit_unix_group_get_gid(self.to_glib_none().0) }
27    }
28
29    #[doc(alias = "polkit_unix_group_set_gid")]
30    #[doc(alias = "gid")]
31    pub fn set_gid(&self, gid: i32) {
32        unsafe {
33            ffi::polkit_unix_group_set_gid(self.to_glib_none().0, gid);
34        }
35    }
36
37    #[allow(clippy::new_ret_no_self)]
38    #[doc(alias = "polkit_unix_group_new")]
39    pub fn new(gid: i32) -> Self {
40        unsafe {
41            let identify: Identity = from_glib_full(ffi::polkit_unix_group_new(gid));
42            identify.unsafe_cast()
43        }
44    }
45
46    #[doc(alias = "polkit_unix_group_new_for_name")]
47    pub fn new_for_name(name: &str) -> Result<Self, glib::Error> {
48        unsafe {
49            let mut error = std::ptr::null_mut();
50            let ret = ffi::polkit_unix_group_new_for_name(name.to_glib_none().0, &mut error);
51            if error.is_null() {
52                let identify: Identity = from_glib_full(ret);
53                Ok(identify.unsafe_cast())
54            } else {
55                Err(from_glib_full(error))
56            }
57        }
58    }
59
60    #[doc(alias = "gid")]
61    pub fn connect_gid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
62        unsafe extern "C" fn notify_gid_trampoline<F: Fn(&UnixGroup) + 'static>(
63            this: *mut ffi::PolkitUnixGroup,
64            _param_spec: glib::ffi::gpointer,
65            f: glib::ffi::gpointer,
66        ) {
67            unsafe {
68                let f: &F = &*(f as *const F);
69                f(&from_glib_borrow(this))
70            }
71        }
72        unsafe {
73            let f: Box_<F> = Box_::new(f);
74            connect_raw(
75                self.as_ptr() as *mut _,
76                c"notify::gid".as_ptr() as *const _,
77                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
78                    notify_gid_trampoline::<F> as *const (),
79                )),
80                Box_::into_raw(f),
81            )
82        }
83    }
84}