polkit_rs/auto/
subject.rs

1// Generated by gir (https://github.com/gtk-rs/gir @ b2a1c6f9b362)
2// from ../misc (@ ???)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{prelude::*, translate::*};
7use std::{boxed::Box as Box_, pin::Pin};
8
9glib::wrapper! {
10    #[doc(alias = "PolkitSubject")]
11    pub struct Subject(Interface<ffi::PolkitSubject, ffi::PolkitSubjectIface>);
12
13    match fn {
14        type_ => || ffi::polkit_subject_get_type(),
15    }
16}
17
18impl Subject {
19    pub const NONE: Option<&'static Subject> = None;
20
21    #[doc(alias = "polkit_subject_from_string")]
22    pub fn from_string(str: &str) -> Result<Subject, glib::Error> {
23        unsafe {
24            let mut error = std::ptr::null_mut();
25            let ret = ffi::polkit_subject_from_string(str.to_glib_none().0, &mut error);
26            if error.is_null() {
27                Ok(from_glib_full(ret))
28            } else {
29                Err(from_glib_full(error))
30            }
31        }
32    }
33}
34
35pub trait SubjectExt: IsA<Subject> + 'static {
36    #[doc(alias = "polkit_subject_equal")]
37    fn equal(&self, b: &impl IsA<Subject>) -> bool {
38        unsafe {
39            from_glib(ffi::polkit_subject_equal(
40                self.as_ref().to_glib_none().0,
41                b.as_ref().to_glib_none().0,
42            ))
43        }
44    }
45
46    #[doc(alias = "polkit_subject_exists")]
47    fn exists<P: FnOnce(Result<(), glib::Error>) + 'static>(
48        &self,
49        cancellable: Option<&impl IsA<gio::Cancellable>>,
50        callback: P,
51    ) {
52        let main_context = glib::MainContext::ref_thread_default();
53        let is_main_context_owner = main_context.is_owner();
54        let has_acquired_main_context = (!is_main_context_owner)
55            .then(|| main_context.acquire().ok())
56            .flatten();
57        assert!(
58            is_main_context_owner || has_acquired_main_context.is_some(),
59            "Async operations only allowed if the thread is owning the MainContext"
60        );
61
62        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
63            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
64        unsafe extern "C" fn exists_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
65            _source_object: *mut glib::gobject_ffi::GObject,
66            res: *mut gio::ffi::GAsyncResult,
67            user_data: glib::ffi::gpointer,
68        ) {
69            unsafe {
70                let mut error = std::ptr::null_mut();
71                ffi::polkit_subject_exists_finish(_source_object as *mut _, res, &mut error);
72                let result = if error.is_null() {
73                    Ok(())
74                } else {
75                    Err(from_glib_full(error))
76                };
77                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
78                    Box_::from_raw(user_data as *mut _);
79                let callback: P = callback.into_inner();
80                callback(result);
81            }
82        }
83        let callback = exists_trampoline::<P>;
84        unsafe {
85            ffi::polkit_subject_exists(
86                self.as_ref().to_glib_none().0,
87                cancellable.map(|p| p.as_ref()).to_glib_none().0,
88                Some(callback),
89                Box_::into_raw(user_data) as *mut _,
90            );
91        }
92    }
93
94    fn exists_future(
95        &self,
96    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
97        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
98            obj.exists(Some(cancellable), move |res| {
99                send.resolve(res);
100            });
101        }))
102    }
103
104    #[doc(alias = "polkit_subject_exists_sync")]
105    fn exists_sync(
106        &self,
107        cancellable: Option<&impl IsA<gio::Cancellable>>,
108    ) -> Result<(), glib::Error> {
109        unsafe {
110            let mut error = std::ptr::null_mut();
111            let is_ok = ffi::polkit_subject_exists_sync(
112                self.as_ref().to_glib_none().0,
113                cancellable.map(|p| p.as_ref()).to_glib_none().0,
114                &mut error,
115            );
116            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
117            if error.is_null() {
118                Ok(())
119            } else {
120                Err(from_glib_full(error))
121            }
122        }
123    }
124
125    #[doc(alias = "polkit_subject_hash")]
126    fn hash(&self) -> u32 {
127        unsafe { ffi::polkit_subject_hash(self.as_ref().to_glib_none().0) }
128    }
129
130    #[doc(alias = "polkit_subject_to_string")]
131    fn to_string(&self) -> glib::GString {
132        unsafe {
133            from_glib_full(ffi::polkit_subject_to_string(
134                self.as_ref().to_glib_none().0,
135            ))
136        }
137    }
138}
139
140impl<O: IsA<Subject>> SubjectExt for O {}