gio/auto/cancellable.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[doc(alias = "GCancellable")]
10 pub struct Cancellable(Object<ffi::GCancellable, ffi::GCancellableClass>);
11
12 match fn {
13 type_ => || ffi::g_cancellable_get_type(),
14 }
15}
16
17impl Cancellable {
18 pub const NONE: Option<&'static Cancellable> = None;
19
20 #[doc(alias = "g_cancellable_new")]
21 pub fn new() -> Cancellable {
22 unsafe { from_glib_full(ffi::g_cancellable_new()) }
23 }
24
25 #[doc(alias = "g_cancellable_get_current")]
26 #[doc(alias = "get_current")]
27 pub fn current() -> Option<Cancellable> {
28 unsafe { from_glib_none(ffi::g_cancellable_get_current()) }
29 }
30}
31
32impl Default for Cancellable {
33 fn default() -> Self {
34 Self::new()
35 }
36}
37
38unsafe impl Send for Cancellable {}
39unsafe impl Sync for Cancellable {}
40
41mod sealed {
42 pub trait Sealed {}
43 impl<T: super::IsA<super::Cancellable>> Sealed for T {}
44}
45
46pub trait CancellableExt: IsA<Cancellable> + sealed::Sealed + 'static {
47 #[doc(alias = "g_cancellable_cancel")]
48 fn cancel(&self) {
49 unsafe {
50 ffi::g_cancellable_cancel(self.as_ref().to_glib_none().0);
51 }
52 }
53
54 #[doc(alias = "g_cancellable_get_fd")]
55 #[doc(alias = "get_fd")]
56 fn fd(&self) -> i32 {
57 unsafe { ffi::g_cancellable_get_fd(self.as_ref().to_glib_none().0) }
58 }
59
60 #[doc(alias = "g_cancellable_is_cancelled")]
61 fn is_cancelled(&self) -> bool {
62 unsafe {
63 from_glib(ffi::g_cancellable_is_cancelled(
64 self.as_ref().to_glib_none().0,
65 ))
66 }
67 }
68
69 //#[doc(alias = "g_cancellable_make_pollfd")]
70 //fn make_pollfd(&self, pollfd: /*Ignored*/&mut glib::PollFD) -> bool {
71 // unsafe { TODO: call ffi:g_cancellable_make_pollfd() }
72 //}
73
74 #[doc(alias = "g_cancellable_pop_current")]
75 fn pop_current(&self) {
76 unsafe {
77 ffi::g_cancellable_pop_current(self.as_ref().to_glib_none().0);
78 }
79 }
80
81 #[doc(alias = "g_cancellable_push_current")]
82 fn push_current(&self) {
83 unsafe {
84 ffi::g_cancellable_push_current(self.as_ref().to_glib_none().0);
85 }
86 }
87
88 #[doc(alias = "g_cancellable_release_fd")]
89 fn release_fd(&self) {
90 unsafe {
91 ffi::g_cancellable_release_fd(self.as_ref().to_glib_none().0);
92 }
93 }
94}
95
96impl<O: IsA<Cancellable>> CancellableExt for O {}