libappstream 0.4.0

Rust bindings for appstream
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::{ffi, Component};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    #[doc(alias = "AsComponentBox")]
    pub struct ComponentBox(Object<ffi::AsComponentBox, ffi::AsComponentBoxClass>);

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

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

    //#[doc(alias = "as_component_box_new")]
    //pub fn new(flags: /*Ignored*/ComponentBoxFlags) -> ComponentBox {
    //    unsafe { TODO: call ffi:as_component_box_new() }
    //}

    #[doc(alias = "as_component_box_new_simple")]
    pub fn new_simple() -> ComponentBox {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::as_component_box_new_simple()) }
    }
}

pub trait ComponentBoxExt: IsA<ComponentBox> + 'static {
    #[doc(alias = "as_component_box_add")]
    fn add(&self, cpt: &impl IsA<Component>) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::as_component_box_add(
                self.as_ref().to_glib_none().0,
                cpt.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))
            }
        }
    }

    #[doc(alias = "as_component_box_as_array")]
    fn as_array(&self) -> Vec<Component> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::as_component_box_as_array(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "as_component_box_clear")]
    fn clear(&self) {
        unsafe {
            ffi::as_component_box_clear(self.as_ref().to_glib_none().0);
        }
    }

    //#[doc(alias = "as_component_box_get_flags")]
    //#[doc(alias = "get_flags")]
    //fn flags(&self) -> /*Ignored*/ComponentBoxFlags {
    //    unsafe { TODO: call ffi:as_component_box_get_flags() }
    //}

    #[doc(alias = "as_component_box_get_size")]
    #[doc(alias = "get_size")]
    fn size(&self) -> u32 {
        unsafe { ffi::as_component_box_get_size(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "as_component_box_index_safe")]
    fn index_safe(&self, index: u32) -> Option<Component> {
        unsafe {
            from_glib_none(ffi::as_component_box_index_safe(
                self.as_ref().to_glib_none().0,
                index,
            ))
        }
    }

    #[doc(alias = "as_component_box_is_empty")]
    fn is_empty(&self) -> bool {
        unsafe {
            from_glib(ffi::as_component_box_is_empty(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "as_component_box_remove_at")]
    fn remove_at(&self, index: u32) {
        unsafe {
            ffi::as_component_box_remove_at(self.as_ref().to_glib_none().0, index);
        }
    }

    #[doc(alias = "as_component_box_sort")]
    fn sort(&self) {
        unsafe {
            ffi::as_component_box_sort(self.as_ref().to_glib_none().0);
        }
    }

    #[doc(alias = "as_component_box_sort_by_score")]
    fn sort_by_score(&self) {
        unsafe {
            ffi::as_component_box_sort_by_score(self.as_ref().to_glib_none().0);
        }
    }
}

impl<O: IsA<ComponentBox>> ComponentBoxExt for O {}