Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/yew-macro/tests/html_macro/for-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,13 @@ fn main() {
</div>
}
}

let children = ::yew::Children::new(::std::vec![::yew::html! { <span>{"x"}</span> }]);
_ = ::yew::html! {
<ul>
for child in &children {
<li>{child}</li>
}
</ul>
};
}
9 changes: 9 additions & 0 deletions packages/yew/src/html/component/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ impl<T: Clone> IntoIterator for ChildrenRenderer<T> {
}
}

impl<T: Clone> IntoIterator for &ChildrenRenderer<T> {
type IntoIter = std::vec::IntoIter<Self::Item>;
type Item = T;

fn into_iter(self) -> Self::IntoIter {
self.iter().collect::<Vec<_>>().into_iter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could return just self.iter() and avoid the clone of the whole Vec with more precise types, I believe.

I do note that with some self-referential tricks, the above impl for ChildrenRenderer<T> could do the same, clone just the Rc instead of the whole Vec. Being able to just take a reference to the contained Vec without carrying around the owner should be a lot simpler in this case though.

}
}

impl From<ChildrenRenderer<Html>> for Html {
fn from(mut val: ChildrenRenderer<Html>) -> Self {
if let Some(children) = val.children.as_mut() {
Expand Down
Loading