File tree Expand file tree Collapse file tree 4 files changed +37
-20
lines changed Expand file tree Collapse file tree 4 files changed +37
-20
lines changed Original file line number Diff line number Diff line change @@ -81,10 +81,14 @@ impl FuzzySelect<'_> {
81
81
}
82
82
83
83
/// Adds multiple items to the fuzzy selector.
84
- pub fn items < T : ToString > ( mut self , items : & [ T ] ) -> Self {
85
- for item in items {
86
- self . items . push ( item. to_string ( ) ) ;
87
- }
84
+ pub fn items < T , I > ( mut self , items : I ) -> Self
85
+ where
86
+ T : ToString ,
87
+ I : IntoIterator < Item = T > ,
88
+ {
89
+ self . items
90
+ . extend ( items. into_iter ( ) . map ( |item| item. to_string ( ) ) ) ;
91
+
88
92
self
89
93
}
90
94
Original file line number Diff line number Diff line change @@ -101,17 +101,21 @@ impl MultiSelect<'_> {
101
101
}
102
102
103
103
/// Adds multiple items to the selector.
104
- pub fn items < T : ToString > ( mut self , items : & [ T ] ) -> Self {
105
- for item in items {
106
- self . items . push ( item . to_string ( ) ) ;
107
- self . defaults . push ( false ) ;
108
- }
109
- self
104
+ pub fn items < T , I > ( self , items : I ) -> Self
105
+ where
106
+ T : ToString ,
107
+ I : IntoIterator < Item = T > ,
108
+ {
109
+ self . items_checked ( items . into_iter ( ) . map ( |item| ( item , false ) ) )
110
110
}
111
111
112
112
/// Adds multiple items to the selector with checked state
113
- pub fn items_checked < T : ToString > ( mut self , items : & [ ( T , bool ) ] ) -> Self {
114
- for & ( ref item, checked) in items {
113
+ pub fn items_checked < T , I > ( mut self , items : I ) -> Self
114
+ where
115
+ T : ToString ,
116
+ I : IntoIterator < Item = ( T , bool ) > ,
117
+ {
118
+ for ( item, checked) in items. into_iter ( ) {
115
119
self . items . push ( item. to_string ( ) ) ;
116
120
self . defaults . push ( checked) ;
117
121
}
Original file line number Diff line number Diff line change @@ -99,14 +99,19 @@ impl Select<'_> {
99
99
/// ```
100
100
pub fn item < T : ToString > ( mut self , item : T ) -> Self {
101
101
self . items . push ( item. to_string ( ) ) ;
102
+
102
103
self
103
104
}
104
105
105
106
/// Adds multiple items to the selector.
106
- pub fn items < T : ToString > ( mut self , items : & [ T ] ) -> Self {
107
- for item in items {
108
- self . items . push ( item. to_string ( ) ) ;
109
- }
107
+ pub fn items < T , I > ( mut self , items : I ) -> Self
108
+ where
109
+ T : ToString ,
110
+ I : IntoIterator < Item = T > ,
111
+ {
112
+ self . items
113
+ . extend ( items. into_iter ( ) . map ( |item| item. to_string ( ) ) ) ;
114
+
110
115
self
111
116
}
112
117
Original file line number Diff line number Diff line change @@ -83,10 +83,14 @@ impl Sort<'_> {
83
83
}
84
84
85
85
/// Adds multiple items to the selector.
86
- pub fn items < T : ToString > ( mut self , items : & [ T ] ) -> Self {
87
- for item in items {
88
- self . items . push ( item. to_string ( ) ) ;
89
- }
86
+ pub fn items < T , I > ( mut self , items : I ) -> Self
87
+ where
88
+ T : ToString ,
89
+ I : IntoIterator < Item = T > ,
90
+ {
91
+ self . items
92
+ . extend ( items. into_iter ( ) . map ( |item| item. to_string ( ) ) ) ;
93
+
90
94
self
91
95
}
92
96
You can’t perform that action at this time.
0 commit comments