File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,16 @@ impl ListStore {
107
107
}
108
108
}
109
109
110
+ impl < P : IsA < glib:: Object > > std:: iter:: FromIterator < P > for ListStore {
111
+ fn from_iter < I : IntoIterator < Item = P > > ( iter : I ) -> Self {
112
+ let store = Self :: new ( P :: static_type ( ) ) ;
113
+ for item in iter. into_iter ( ) {
114
+ store. append ( & item)
115
+ }
116
+ store
117
+ }
118
+ }
119
+
110
120
impl < ' a > std:: iter:: IntoIterator for & ' a ListStore {
111
121
type Item = <& ' a ListModel as IntoIterator >:: Item ;
112
122
type IntoIter = <& ' a ListModel as IntoIterator >:: IntoIter ;
@@ -169,4 +179,15 @@ mod tests {
169
179
list_from_slice. extend_from_slice ( & [ item0, item1. clone ( ) ] ) ;
170
180
assert_eq ! ( list_from_slice. item( 1 ) . as_ref( ) , Some ( item1. upcast_ref( ) ) ) ;
171
181
}
182
+
183
+ #[ test]
184
+ fn from_iterator ( ) {
185
+ let item0 = ListStore :: new ( ListStore :: static_type ( ) ) ;
186
+ let item1 = ListStore :: new ( ListStore :: static_type ( ) ) ;
187
+ let v = vec ! [ item0. clone( ) , item1. clone( ) ] ;
188
+ let list = ListStore :: from_iter ( v) ;
189
+ assert_eq ! ( list. item( 0 ) . as_ref( ) , Some ( item0. upcast_ref( ) ) ) ;
190
+ assert_eq ! ( list. item( 1 ) . as_ref( ) , Some ( item1. upcast_ref( ) ) ) ;
191
+ assert_eq ! ( list. item( 2 ) . as_ref( ) , None ) ;
192
+ }
172
193
}
You can’t perform that action at this time.
0 commit comments