gio/auto/
list_store.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, ListModel};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    #[doc(alias = "GListStore")]
10    pub struct ListStore(Object<ffi::GListStore, ffi::GListStoreClass>) @implements ListModel;
11
12    match fn {
13        type_ => || ffi::g_list_store_get_type(),
14    }
15}
16
17impl ListStore {
18    // rustdoc-stripper-ignore-next
19    /// Creates a new builder-pattern struct instance to construct [`ListStore`] objects.
20    ///
21    /// This method returns an instance of [`ListStoreBuilder`](crate::builders::ListStoreBuilder) which can be used to create [`ListStore`] objects.
22    pub fn builder() -> ListStoreBuilder {
23        ListStoreBuilder::new()
24    }
25
26    #[doc(alias = "g_list_store_append")]
27    pub fn append(&self, item: &impl IsA<glib::Object>) {
28        unsafe {
29            ffi::g_list_store_append(self.to_glib_none().0, item.as_ref().to_glib_none().0);
30        }
31    }
32
33    #[cfg(feature = "v2_64")]
34    #[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
35    #[doc(alias = "g_list_store_find")]
36    pub fn find(&self, item: &impl IsA<glib::Object>) -> Option<u32> {
37        unsafe {
38            let mut position = std::mem::MaybeUninit::uninit();
39            let ret = from_glib(ffi::g_list_store_find(
40                self.to_glib_none().0,
41                item.as_ref().to_glib_none().0,
42                position.as_mut_ptr(),
43            ));
44            if ret {
45                Some(position.assume_init())
46            } else {
47                None
48            }
49        }
50    }
51
52    #[doc(alias = "g_list_store_insert")]
53    pub fn insert(&self, position: u32, item: &impl IsA<glib::Object>) {
54        unsafe {
55            ffi::g_list_store_insert(
56                self.to_glib_none().0,
57                position,
58                item.as_ref().to_glib_none().0,
59            );
60        }
61    }
62
63    #[doc(alias = "g_list_store_remove")]
64    pub fn remove(&self, position: u32) {
65        unsafe {
66            ffi::g_list_store_remove(self.to_glib_none().0, position);
67        }
68    }
69
70    #[doc(alias = "g_list_store_remove_all")]
71    pub fn remove_all(&self) {
72        unsafe {
73            ffi::g_list_store_remove_all(self.to_glib_none().0);
74        }
75    }
76}
77
78// rustdoc-stripper-ignore-next
79/// A [builder-pattern] type to construct [`ListStore`] objects.
80///
81/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
82#[must_use = "The builder must be built to be used"]
83pub struct ListStoreBuilder {
84    builder: glib::object::ObjectBuilder<'static, ListStore>,
85}
86
87impl ListStoreBuilder {
88    fn new() -> Self {
89        Self {
90            builder: glib::object::Object::builder(),
91        }
92    }
93
94    pub fn item_type(self, item_type: glib::types::Type) -> Self {
95        Self {
96            builder: self.builder.property("item-type", item_type),
97        }
98    }
99
100    // rustdoc-stripper-ignore-next
101    /// Build the [`ListStore`].
102    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
103    pub fn build(self) -> ListStore {
104        self.builder.build()
105    }
106}