1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Cancellable;
use glib::{prelude::*, translate::*};

glib::wrapper! {
    #[doc(alias = "GInitable")]
    pub struct Initable(Interface<ffi::GInitable, ffi::GInitableIface>);

    match fn {
        type_ => || ffi::g_initable_get_type(),
    }
}

impl Initable {
    pub const NONE: Option<&'static Initable> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Initable>> Sealed for T {}
}

pub trait InitableExt: IsA<Initable> + sealed::Sealed + 'static {
    #[doc(alias = "g_initable_init")]
    unsafe fn init(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<(), glib::Error> {
        let mut error = std::ptr::null_mut();
        let is_ok = ffi::g_initable_init(
            self.as_ref().to_glib_none().0,
            cancellable.map(|p| p.as_ref()).to_glib_none().0,
            &mut error,
        );
        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
        if error.is_null() {
            Ok(())
        } else {
            Err(from_glib_full(error))
        }
    }
}

impl<O: IsA<Initable>> InitableExt for O {}