// 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::object::IsA;
use glib::translate::*;
use std::fmt;
use std::ptr;

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

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

pub const NONE_INITABLE: Option<&Initable> = None;

pub trait InitableExt: 'static {
    #[doc(alias = "g_initable_init")]
    unsafe fn init<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<(), glib::Error>;
}

impl<O: IsA<Initable>> InitableExt for O {
    unsafe fn init<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<(), glib::Error> {
        let mut error = ptr::null_mut();
        let _ = ffi::g_initable_init(
            self.as_ref().to_glib_none().0,
            cancellable.map(|p| p.as_ref()).to_glib_none().0,
            &mut error,
        );
        if error.is_null() {
            Ok(())
        } else {
            Err(from_glib_full(error))
        }
    }
}

impl fmt::Display for Initable {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Initable")
    }
}
