@@ -7,6 +7,16 @@ use glib::{prelude::*, translate::*, Object};
7
7
use crate :: { prelude:: * , ListModel , ListStore } ;
8
8
9
9
impl ListStore {
10
+ #[ doc( alias = "g_list_store_new" ) ]
11
+ pub fn new < T : StaticType > ( ) -> Self {
12
+ Self :: with_type ( T :: static_type ( ) )
13
+ }
14
+
15
+ #[ doc( alias = "g_list_store_new" ) ]
16
+ pub fn with_type ( type_ : glib:: types:: Type ) -> Self {
17
+ unsafe { from_glib_full ( ffi:: g_list_store_new ( type_. into_glib ( ) ) ) }
18
+ }
19
+
10
20
#[ doc( alias = "g_list_store_insert_sorted" ) ]
11
21
pub fn insert_sorted < P : IsA < glib:: Object > , F : FnMut ( & Object , & Object ) -> Ordering > (
12
22
& self ,
@@ -119,7 +129,7 @@ impl ListStore {
119
129
120
130
impl < P : IsA < glib:: Object > > std:: iter:: FromIterator < P > for ListStore {
121
131
fn from_iter < I : IntoIterator < Item = P > > ( iter : I ) -> Self {
122
- let store = Self :: new ( P :: static_type ( ) ) ;
132
+ let store = Self :: new :: < P > ( ) ;
123
133
for item in iter. into_iter ( ) {
124
134
store. append ( & item)
125
135
}
@@ -165,35 +175,35 @@ mod tests {
165
175
166
176
#[ test]
167
177
fn splice ( ) {
168
- let item0 = ListStore :: new ( ListStore :: static_type ( ) ) ;
169
- let item1 = ListStore :: new ( ListStore :: static_type ( ) ) ;
170
- let list = ListStore :: new ( ListStore :: static_type ( ) ) ;
178
+ let item0 = ListStore :: new :: < ListStore > ( ) ;
179
+ let item1 = ListStore :: new :: < ListStore > ( ) ;
180
+ let list = ListStore :: new :: < ListStore > ( ) ;
171
181
list. splice ( 0 , 0 , & [ item0. clone ( ) , item1. clone ( ) ] ) ;
172
182
assert_eq ! ( list. item( 0 ) , Some ( item0. upcast( ) ) ) ;
173
183
assert_eq ! ( list. item( 1 ) , Some ( item1. upcast( ) ) ) ;
174
184
}
175
185
176
186
#[ test]
177
187
fn extend ( ) {
178
- let item0 = ListStore :: new ( ListStore :: static_type ( ) ) ;
179
- let item1 = ListStore :: new ( ListStore :: static_type ( ) ) ;
180
- let mut list = ListStore :: new ( ListStore :: static_type ( ) ) ;
188
+ let item0 = ListStore :: new :: < ListStore > ( ) ;
189
+ let item1 = ListStore :: new :: < ListStore > ( ) ;
190
+ let mut list = ListStore :: new :: < ListStore > ( ) ;
181
191
list. extend ( [ & item0, & item1] ) ;
182
192
assert_eq ! ( list. item( 0 ) . as_ref( ) , Some ( item0. upcast_ref( ) ) ) ;
183
193
assert_eq ! ( list. item( 1 ) . as_ref( ) , Some ( item1. upcast_ref( ) ) ) ;
184
194
list. extend ( [ item0. clone ( ) , item1. clone ( ) ] ) ;
185
195
assert_eq ! ( list. item( 2 ) . as_ref( ) , Some ( item0. upcast_ref( ) ) ) ;
186
196
assert_eq ! ( list. item( 3 ) . as_ref( ) , Some ( item1. upcast_ref( ) ) ) ;
187
197
188
- let list_from_slice = ListStore :: new ( ListStore :: static_type ( ) ) ;
198
+ let list_from_slice = ListStore :: new :: < ListStore > ( ) ;
189
199
list_from_slice. extend_from_slice ( & [ item0, item1. clone ( ) ] ) ;
190
200
assert_eq ! ( list_from_slice. item( 1 ) . as_ref( ) , Some ( item1. upcast_ref( ) ) ) ;
191
201
}
192
202
193
203
#[ test]
194
204
fn from_iterator ( ) {
195
- let item0 = ListStore :: new ( ListStore :: static_type ( ) ) ;
196
- let item1 = ListStore :: new ( ListStore :: static_type ( ) ) ;
205
+ let item0 = ListStore :: new :: < ListStore > ( ) ;
206
+ let item1 = ListStore :: new :: < ListStore > ( ) ;
197
207
let v = vec ! [ item0. clone( ) , item1. clone( ) ] ;
198
208
let list = ListStore :: from_iter ( v) ;
199
209
assert_eq ! ( list. item( 0 ) . as_ref( ) , Some ( item0. upcast_ref( ) ) ) ;
@@ -204,9 +214,9 @@ mod tests {
204
214
#[ cfg( feature = "v2_74" ) ]
205
215
#[ test]
206
216
fn find ( ) {
207
- let item0 = ListStore :: new ( ListStore :: static_type ( ) ) ;
208
- let item1 = ListStore :: new ( ListStore :: static_type ( ) ) ;
209
- let list = ListStore :: new ( ListStore :: static_type ( ) ) ;
217
+ let item0 = ListStore :: new :: < ListStore > ( ) ;
218
+ let item1 = ListStore :: new :: < ListStore > ( ) ;
219
+ let list = ListStore :: new :: < ListStore > ( ) ;
210
220
list. append ( & item0) ;
211
221
list. append ( & item1) ;
212
222
0 commit comments