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::{ffi, Cancellable};
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        let mut error = std::ptr::null_mut();
25        let is_ok = ffi::g_initable_init(
26            self.as_ref().to_glib_none().0,
27            cancellable.map(|p| p.as_ref()).to_glib_none().0,
28            &mut error,
29        );
30        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
31        if error.is_null() {
32            Ok(())
33        } else {
34            Err(from_glib_full(error))
35        }
36    }
37}
38
39impl<O: IsA<Initable>> InitableExt for O {}