Support Rc in html! attributes #1851
Labels
A-yew
Area: The main yew crate
A-yew-macro
Area: The yew-macro crate
feature-accepted
A feature request that has been accepted and needs implementing
feature-request
A feature request
Yew 0.17.4 silently cloned Strings passed in e.g.
html!{<p foo=&self.a_String}
.String::clone
copies the contents of the string, which is wasteful.v0.18.0 removes the silent clone, and while the easy fix would be to just move the clone up the stack to my
Component::view
, copying string contents on every view seems wasteful. That was the motivation for the change in the first place!At first, it seems using
Cow
would help, but after some discussion I believe the current use ofCow<'static, str>
still causes String content copies when the string has a lifetime less than'static
, e.g. strings originating from messages toComponent::update
.It seems using
Rc<str>
or such would lead to string content copying happening only inComponent::update
(and typically, only for one variant of theComponent::Message
enum), so that would be a nice improvement.It would be great if yew's vdom understood
Rc<str>
(and perhapsArc
also) and allowed using reference counts to enable cheap clones, instead of expensive string content copies.Concretely:
It should also be possible to push the Rc (or just str) up front all the way to the message source, to avoid even the copy in `Component::update``, but that shouldn't require anything from yew.
The text was updated successfully, but these errors were encountered: