Skip to main content

gio/auto/
initable.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::{Cancellable, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    #[doc(alias = "GInitable")]
10    pub struct Initable(Interface<ffi::GInitable, ffi::GInitableIface>);
11
12    match fn {
13        type_ => || ffi::g_initable_get_type(),
14    }
15}
16
17impl Initable {
18    pub const NONE: Option<&'static Initable> = None;
19}
20
21pub trait InitableExt: IsA<Initable> + 'static {
22    #[doc(alias = "g_initable_init")]
23    unsafe fn init(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<(), glib::Error> {
24        unsafe {
25            let mut error = std::ptr::null_mut();
26            let is_ok = ffi::g_initable_init(
27                self.as_ref().to_glib_none().0,
28                cancellable.map(|p| p.as_ref()).to_glib_none().0,
29                &mut error,
30            );
31            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
32            if error.is_null() {
33                Ok(())
34            } else {
35                Err(from_glib_full(error))
36            }
37        }
38    }
39}
40
41impl<O: IsA<Initable>> InitableExt for O {}