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
41pub trait CancellableExt: IsA<Cancellable> + 'static {
42    #[doc(alias = "g_cancellable_cancel")]
43    fn cancel(&self) {
44        unsafe {
45            ffi::g_cancellable_cancel(self.as_ref().to_glib_none().0);
46        }
47    }
48
49    #[doc(alias = "g_cancellable_get_fd")]
50    #[doc(alias = "get_fd")]
51    fn fd(&self) -> i32 {
52        unsafe { ffi::g_cancellable_get_fd(self.as_ref().to_glib_none().0) }
53    }
54
55    #[doc(alias = "g_cancellable_is_cancelled")]
56    fn is_cancelled(&self) -> bool {
57        unsafe {
58            from_glib(ffi::g_cancellable_is_cancelled(
59                self.as_ref().to_glib_none().0,
60            ))
61        }
62    }
63
64    //#[doc(alias = "g_cancellable_make_pollfd")]
65    //fn make_pollfd(&self, pollfd: /*Ignored*/&mut glib::PollFD) -> bool {
66    //    unsafe { TODO: call ffi:g_cancellable_make_pollfd() }
67    //}
68
69    #[doc(alias = "g_cancellable_pop_current")]
70    fn pop_current(&self) {
71        unsafe {
72            ffi::g_cancellable_pop_current(self.as_ref().to_glib_none().0);
73        }
74    }
75
76    #[doc(alias = "g_cancellable_push_current")]
77    fn push_current(&self) {
78        unsafe {
79            ffi::g_cancellable_push_current(self.as_ref().to_glib_none().0);
80        }
81    }
82
83    #[doc(alias = "g_cancellable_release_fd")]
84    fn release_fd(&self) {
85        unsafe {
86            ffi::g_cancellable_release_fd(self.as_ref().to_glib_none().0);
87        }
88    }
89}
90
91impl<O: IsA<Cancellable>> CancellableExt for O {}