@@ -95,12 +95,25 @@ impl<Ms> UpdateEl<El<Ms>> for WillUnmount<Ms> {
9595}
9696
9797impl < Ms > UpdateEl < El < Ms > > for & str {
98- // This, or some other mechanism seems to work for String too... note sure why.
9998 fn update ( self , el : & mut El < Ms > ) {
10099 el. children . push ( Node :: Text ( Text :: new ( self . to_string ( ) ) ) )
101100 }
102101}
103102
103+ // In the most cases `&str` is enough,
104+ // but if we have, for instance, `Filter` iterator of `String`s -
105+ // then the Rust type system can't coerce `String` to `&str`.
106+ //
107+ // However if we implement `UpdateEl` for `String`, code like `h1![model.title]` cannot be compiled,
108+ // because Rust chooses `String` impl instead of `&str` and fails on moving value (`title`).
109+ // @TODO How to resolve it? `&self`?
110+ //
111+ //impl<Ms> UpdateEl<El<Ms>> for String {
112+ // fn update(self, el: &mut El<Ms>) {
113+ // el.children.push(Node::Text(Text::new(self)))
114+ // }
115+ //}
116+
104117impl < Ms > UpdateEl < El < Ms > > for El < Ms > {
105118 fn update ( self , el : & mut El < Ms > ) {
106119 el. children . push ( Node :: Element ( self ) )
@@ -133,6 +146,8 @@ impl<Ms> UpdateEl<El<Ms>> for Tag {
133146 }
134147}
135148
149+ // ----- Iterators ------
150+
136151impl < Ms , I , U , F > UpdateEl < El < Ms > > for std:: iter:: Map < I , F >
137152where
138153 I : Iterator ,
@@ -144,57 +159,24 @@ where
144159 }
145160}
146161
147- // impl<Ms, I, U, P> UpdateEl<El<Ms>> for std::iter::Filter<I, P>
148- // where
149- // I: Iterator,
150- // U: UpdateEl<El<Ms>>,
151- // P: FnMut(&I::Item) -> bool,
152- // {
153- // fn update(self, el: &mut El<Ms>) {
154- // self.for_each(|item| item.update(el));
155- // }
156- // }
157-
158- //impl<Ms, I, U, F> UpdateEl<El<Ms>> for std::iter::Map<I, F>
159- //where
160- // I: Iterator,
161- // U: UpdateEl<Attrs>,
162- // F: FnMut(I::Item) -> U,
163- //{
164- // fn update(self, el: &mut El<Ms>) {
165- // self.for_each(|item| item.update(el));
166- // }
167- //}
168- //
169- //impl<Ms, I, U, F> UpdateEl<El<Ms>> for std::iter::Map<I, F>
170- //where
171- // I: Iterator,
172- // U: UpdateEl<&Attrs>,
173- // F: FnMut(I::Item) -> U,
174- //{
175- // fn update(self, el: &mut El<Ms>) {
176- // self.for_each(|item| item.update(el));
177- // }
178- //}
179- //
180- //impl<Ms, I, U, F> UpdateEl<El<Ms>> for std::iter::Map<I, F>
181- //where
182- // I: Iterator,
183- // U: UpdateEl<Style>,
184- // F: FnMut(I::Item) -> U,
185- //{
186- // fn update(self, el: &mut El<Ms>) {
187- // self.for_each(|item| item.update(el));
188- // }
189- //}
190- //
191- //impl<Ms, I, U, F> UpdateEl<El<Ms>> for std::iter::Map<I, F>
192- //where
193- // I: Iterator,
194- // U: UpdateEl<&Style>,
195- // F: FnMut(I::Item) -> U,
196- //{
197- // fn update(self, el: &mut El<Ms>) {
198- // self.for_each(|item| item.update(el));
199- // }
200- //}
162+ impl < Ms , I , U , F > UpdateEl < El < Ms > > for std:: iter:: FilterMap < I , F >
163+ where
164+ I : Iterator ,
165+ U : UpdateEl < El < Ms > > ,
166+ F : FnMut ( I :: Item ) -> Option < U > ,
167+ {
168+ fn update ( self , el : & mut El < Ms > ) {
169+ self . for_each ( |item| item. update ( el) ) ;
170+ }
171+ }
172+
173+ impl < Ms , I , U , P > UpdateEl < El < Ms > > for std:: iter:: Filter < I , P >
174+ where
175+ U : UpdateEl < El < Ms > > ,
176+ I : Iterator < Item = U > ,
177+ P : FnMut ( & I :: Item ) -> bool ,
178+ {
179+ fn update ( self , el : & mut El < Ms > ) {
180+ self . for_each ( |item| item. update ( el) ) ;
181+ }
182+ }
0 commit comments