1 // Take a look at the license at the top of the repository in the LICENSE file.
2 
3 use crate::traits::InitableExt;
4 use crate::Cancellable;
5 use crate::Initable;
6 use glib::object::IsA;
7 use glib::object::IsClass;
8 use glib::value::ToValue;
9 use glib::Object;
10 
11 impl Initable {
12     #[allow(clippy::new_ret_no_self)]
new<O: Sized + IsClass + IsA<Object> + IsA<Initable>, P: IsA<Cancellable>>( properties: &[(&str, &dyn ToValue)], cancellable: Option<&P>, ) -> Result<O, InitableError>13     pub fn new<O: Sized + IsClass + IsA<Object> + IsA<Initable>, P: IsA<Cancellable>>(
14         properties: &[(&str, &dyn ToValue)],
15         cancellable: Option<&P>,
16     ) -> Result<O, InitableError> {
17         let object = Object::new::<O>(properties)?;
18         unsafe { object.init(cancellable)? };
19         Ok(object)
20     }
21 }
22 
23 #[derive(thiserror::Error, Debug)]
24 pub enum InitableError {
25     #[error("Object::new failed with {0:?}")]
26     NewObjectFailed(#[from] glib::error::BoolError),
27     #[error("Initable::init failed with {0:?}")]
28     InitFailed(#[from] glib::Error),
29 }
30