YoloDev / rstml-component

MIT License
4 stars 2 forks source link

Implement `HtmlContent` for `&String` #22

Closed jonahlund closed 8 months ago

jonahlund commented 8 months ago

This PR implements HtmlContent for &String to make working with strings more convenient

Alxandr commented 8 months ago

I explicitly didn't add this previously, because a &String is generally not something you want to have anywhere, and it dereferences to a &str. What's your usecase for this?

jonahlund commented 8 months ago

Currently, this code gives an error:

let foo = String::new();
let bar = html!(
    <div>{&foo}</div>
);
error[E0277]: the trait bound `&String: HtmlContent` is not satisfied

and to solve it you need to use either foo.as_str(), &foo as &str or &*foo, which is somewhat inconvenient to use

Alxandr commented 8 months ago

Fair enough.