@@ -54,15 +54,15 @@ impl<'a> Atoms<'a> {
54
54
string
55
55
}
56
56
57
- pub fn iter_kinds ( & ' a self ) -> impl Iterator < Item = & ' a AtomKind < ' a > > {
57
+ pub fn iter_kinds ( & self ) -> impl Iterator < Item = & AtomKind < ' a > > {
58
58
self . 0 . iter ( ) . map ( |atom| & atom. kind )
59
59
}
60
60
61
- pub fn iter_kinds_mut ( & ' a mut self ) -> impl Iterator < Item = & ' a mut AtomKind < ' a > > {
61
+ pub fn iter_kinds_mut ( & mut self ) -> impl Iterator < Item = & mut AtomKind < ' a > > {
62
62
self . 0 . iter_mut ( ) . map ( |atom| & mut atom. kind )
63
63
}
64
64
65
- pub fn iter_images ( & ' a self ) -> impl Iterator < Item = & ' a Image < ' a > > {
65
+ pub fn iter_images ( & self ) -> impl Iterator < Item = & Image < ' a > > {
66
66
self . iter_kinds ( ) . filter_map ( |kind| {
67
67
if let AtomKind :: Image ( image) = kind {
68
68
Some ( image)
@@ -72,7 +72,7 @@ impl<'a> Atoms<'a> {
72
72
} )
73
73
}
74
74
75
- pub fn iter_images_mut ( & ' a mut self ) -> impl Iterator < Item = & ' a mut Image < ' a > > {
75
+ pub fn iter_images_mut ( & mut self ) -> impl Iterator < Item = & mut Image < ' a > > {
76
76
self . iter_kinds_mut ( ) . filter_map ( |kind| {
77
77
if let AtomKind :: Image ( image) = kind {
78
78
Some ( image)
@@ -82,7 +82,7 @@ impl<'a> Atoms<'a> {
82
82
} )
83
83
}
84
84
85
- pub fn iter_texts ( & ' a self ) -> impl Iterator < Item = & ' a WidgetText > {
85
+ pub fn iter_texts ( & self ) -> impl Iterator < Item = & WidgetText > + use < ' _ , ' a > {
86
86
self . iter_kinds ( ) . filter_map ( |kind| {
87
87
if let AtomKind :: Text ( text) = kind {
88
88
Some ( text)
@@ -92,7 +92,7 @@ impl<'a> Atoms<'a> {
92
92
} )
93
93
}
94
94
95
- pub fn iter_texts_mut ( & ' a mut self ) -> impl Iterator < Item = & ' a mut WidgetText > {
95
+ pub fn iter_texts_mut ( & mut self ) -> impl Iterator < Item = & mut WidgetText > + use < ' a , ' _ > {
96
96
self . iter_kinds_mut ( ) . filter_map ( |kind| {
97
97
if let AtomKind :: Text ( text) = kind {
98
98
Some ( text)
@@ -107,7 +107,7 @@ impl<'a> Atoms<'a> {
107
107
. for_each ( |atom| * atom = f ( std:: mem:: take ( atom) ) ) ;
108
108
}
109
109
110
- pub fn map_kind < F > ( & ' a mut self , mut f : F )
110
+ pub fn map_kind < F > ( & mut self , mut f : F )
111
111
where
112
112
F : FnMut ( AtomKind < ' a > ) -> AtomKind < ' a > ,
113
113
{
@@ -116,7 +116,7 @@ impl<'a> Atoms<'a> {
116
116
}
117
117
}
118
118
119
- pub fn map_images < F > ( & ' a mut self , mut f : F )
119
+ pub fn map_images < F > ( & mut self , mut f : F )
120
120
where
121
121
F : FnMut ( Image < ' a > ) -> Image < ' a > ,
122
122
{
@@ -129,7 +129,7 @@ impl<'a> Atoms<'a> {
129
129
} ) ;
130
130
}
131
131
132
- pub fn map_texts < F > ( & ' a mut self , mut f : F )
132
+ pub fn map_texts < F > ( & mut self , mut f : F )
133
133
where
134
134
F : FnMut ( WidgetText ) -> WidgetText ,
135
135
{
@@ -227,3 +227,33 @@ impl DerefMut for Atoms<'_> {
227
227
& mut self . 0
228
228
}
229
229
}
230
+
231
+ impl < ' a , T : Into < Atom < ' a > > > From < Vec < T > > for Atoms < ' a > {
232
+ fn from ( vec : Vec < T > ) -> Self {
233
+ Atoms ( vec. into_iter ( ) . map ( Into :: into) . collect ( ) )
234
+ }
235
+ }
236
+
237
+ impl < ' a , T : Into < Atom < ' a > > + Clone > From < & [ T ] > for Atoms < ' a > {
238
+ fn from ( slice : & [ T ] ) -> Self {
239
+ Atoms ( slice. iter ( ) . cloned ( ) . map ( Into :: into) . collect ( ) )
240
+ }
241
+ }
242
+
243
+ impl < ' a , Item : Into < Atom < ' a > > > FromIterator < Item > for Atoms < ' a > {
244
+ fn from_iter < T : IntoIterator < Item = Item > > ( iter : T ) -> Self {
245
+ Atoms ( iter. into_iter ( ) . map ( Into :: into) . collect ( ) )
246
+ }
247
+ }
248
+
249
+ #[ cfg( test) ]
250
+ mod tests {
251
+ use crate :: Atoms ;
252
+
253
+ #[ test]
254
+ fn collect_atoms ( ) {
255
+ let _: Atoms < ' _ > = [ "Hello" , "World" ] . into_iter ( ) . collect ( ) ;
256
+ let _ = Atoms :: from ( vec ! [ "Hi" ] ) ;
257
+ let _ = Atoms :: from ( [ "Hi" ] . as_slice ( ) ) ;
258
+ }
259
+ }
0 commit comments