-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support collecting iterators into VNode #622
Conversation
…t struct to implement Into<VNode> (via From<>) for
Thank you for the PR! 👍 Could you try to implement Does this change gives extra benefits to users instead of straightforward |
Thanks. I wouldn't merge this unless we can get to the aforementioned "ideal" state where you can just dump a value that happens to be convertible to an iterator over html elements into the html! macro and have it work. It would be a change that everyone would have to implement, for the minimal benefit of keeping the "jsx"-y syntax of I'm finding that the original Edit: I don't see the ideal case being possible without trait specialization or mutually exclusive traits landing first, which I'm guessing would take a year at the earliest. |
Agreed, let's keep the |
bors r+ |
622: Remove special 'for' syntax (WIP) r=jstarry a=hgzimmerman Attempts to address #606 I'm running into coherence issues and conflicting implementations with `ToString` and `IntoIterator` when I try to do a blanket impl for `impl <T: IntoIterator<etc...> From<T> for VNode<COMP>`. If I replace the `ToString` blanket impl with concrete impls for `String` and `&str`, I still run into coherence issues where downstream crates might provide a conflicting impl. I figured that the easiest path forward is to create my own iterator and implement `Into<VNode<COMP>>` for it via an impl for `From`. So this PR thusfar gets us from: #### Before ```rust html! { for self.props.items.iter().map(renderItem) } ``` #### To the start of this PR. ```rust html! { self.props.items.iter().map(renderItem).html() } ``` #### To now ```rust html! { self.props.items.iter().map(renderItem).collect::<Html<Self>>() } ``` Which strictly speaking, is _better_, as it frees up a keyword, but isn't anywhere near what you ideally want: #### Ideal ```rust html! { self.props.items.iter().map(renderItem) } ``` ------- Any feedback on how to achieve this design goal would be appreciated. Co-authored-by: Henry Zimmerman <zimhen7@gmail.com>
Build succeeded
|
Attempts to address #606
I'm running into coherence issues and conflicting implementations with
ToString
andIntoIterator
when I try to do a blanket impl forimpl <T: IntoIterator<etc...> From<T> for VNode<COMP>
. If I replace theToString
blanket impl with concrete impls forString
and&str
, I still run into coherence issues where downstream crates might provide a conflicting impl.I figured that the easiest path forward is to create my own iterator and implement
Into<VNode<COMP>>
for it via an impl forFrom
.So this PR thusfar gets us from:
Before
To the start of this PR.
To now
Which strictly speaking, is better, as it frees up a keyword, but isn't anywhere near what you ideally want:
Ideal
Any feedback on how to achieve this design goal would be appreciated.