gio/auto/
list_store.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// 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::{ffi, ListModel};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// `GListStore` is a simple implementation of [`ListModel`][crate::ListModel] that stores
    /// all items in memory.
    ///
    /// It provides insertions, deletions, and lookups in logarithmic time
    /// with a fast path for the common case of iterating the list linearly.
    ///
    /// ## Properties
    ///
    ///
    /// #### `item-type`
    ///  The type of items contained in this list store. Items must be
    /// subclasses of #GObject.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `n-items`
    ///  The number of items contained in this list store.
    ///
    /// Readable
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`], [`ListModelExt`][trait@crate::prelude::ListModelExt], [`ListModelExtManual`][trait@crate::prelude::ListModelExtManual]
    #[doc(alias = "GListStore")]
    pub struct ListStore(Object<ffi::GListStore, ffi::GListStoreClass>) @implements ListModel;

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

impl ListStore {
    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`ListStore`] objects.
    ///
    /// This method returns an instance of [`ListStoreBuilder`](crate::builders::ListStoreBuilder) which can be used to create [`ListStore`] objects.
    pub fn builder() -> ListStoreBuilder {
        ListStoreBuilder::new()
    }

    /// Appends @item to @self. @item must be of type #GListStore:item-type.
    ///
    /// This function takes a ref on @item.
    ///
    /// Use g_list_store_splice() to append multiple items at the same time
    /// efficiently.
    /// ## `item`
    /// the new item
    #[doc(alias = "g_list_store_append")]
    pub fn append(&self, item: &impl IsA<glib::Object>) {
        unsafe {
            ffi::g_list_store_append(self.to_glib_none().0, item.as_ref().to_glib_none().0);
        }
    }

    /// Looks up the given @item in the list store by looping over the items until
    /// the first occurrence of @item. If @item was not found, then @position will
    /// not be set, and this method will return [`false`].
    ///
    /// If you need to compare the two items with a custom comparison function, use
    /// g_list_store_find_with_equal_func() with a custom #GEqualFunc instead.
    /// ## `item`
    /// an item
    ///
    /// # Returns
    ///
    /// Whether @self contains @item. If it was found, @position will be
    /// set to the position where @item occurred for the first time.
    ///
    /// ## `position`
    /// the first position of @item, if it was found.
    #[cfg(feature = "v2_64")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
    #[doc(alias = "g_list_store_find")]
    pub fn find(&self, item: &impl IsA<glib::Object>) -> Option<u32> {
        unsafe {
            let mut position = std::mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::g_list_store_find(
                self.to_glib_none().0,
                item.as_ref().to_glib_none().0,
                position.as_mut_ptr(),
            ));
            if ret {
                Some(position.assume_init())
            } else {
                None
            }
        }
    }

    /// Inserts @item into @self at @position. @item must be of type
    /// #GListStore:item-type or derived from it. @position must be smaller
    /// than the length of the list, or equal to it to append.
    ///
    /// This function takes a ref on @item.
    ///
    /// Use g_list_store_splice() to insert multiple items at the same time
    /// efficiently.
    /// ## `position`
    /// the position at which to insert the new item
    /// ## `item`
    /// the new item
    #[doc(alias = "g_list_store_insert")]
    pub fn insert(&self, position: u32, item: &impl IsA<glib::Object>) {
        unsafe {
            ffi::g_list_store_insert(
                self.to_glib_none().0,
                position,
                item.as_ref().to_glib_none().0,
            );
        }
    }

    /// Removes the item from @self that is at @position. @position must be
    /// smaller than the current length of the list.
    ///
    /// Use g_list_store_splice() to remove multiple items at the same time
    /// efficiently.
    /// ## `position`
    /// the position of the item that is to be removed
    #[doc(alias = "g_list_store_remove")]
    pub fn remove(&self, position: u32) {
        unsafe {
            ffi::g_list_store_remove(self.to_glib_none().0, position);
        }
    }

    /// Removes all items from @self.
    #[doc(alias = "g_list_store_remove_all")]
    pub fn remove_all(&self) {
        unsafe {
            ffi::g_list_store_remove_all(self.to_glib_none().0);
        }
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`ListStore`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct ListStoreBuilder {
    builder: glib::object::ObjectBuilder<'static, ListStore>,
}

impl ListStoreBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    /// The type of items contained in this list store. Items must be
    /// subclasses of #GObject.
    pub fn item_type(self, item_type: glib::types::Type) -> Self {
        Self {
            builder: self.builder.property("item-type", item_type),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`ListStore`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> ListStore {
        self.builder.build()
    }
}