Skip to content
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

impl Render for borrows ? #266

Closed
RCasatta opened this issue Mar 19, 2021 · 3 comments
Closed

impl Render for borrows ? #266

RCasatta opened this issue Mar 19, 2021 · 3 comments
Labels

Comments

@RCasatta
Copy link

I struggled a bit understanding why this code doesn't work

#[test]
fn yet_another_test() {
    let mut vec = vec![];
    let a = html! { div { "foo" } };
    vec.push(a);
    let b = html! { div { "bar" } };
    vec.push(b);
    dbg!(&vec);

    let f = html! { @for el in &vec { (el) } };
    assert_eq!("<div>foo</div><div>bar</div>", f.into_string());
}

before realizing I had to Dereference el -> *el

Maybe it's possible to impl Render for borrowed values ?

@lambda-fairy
Copy link
Owner

That's a good point.

I think it would be possible to add an impl for &PreEscaped<T>.

But I don't think we can generalize beyond that. An impl for all &T will conflict with the existing blanket impl for T: Display, because Display is implemented for all &T already.

I think the ideal solution is to remove the blanket impl for T: Display. This is what markup.rs and sailfish do. But we'll need to check how much code that breaks.

@RCasatta
Copy link
Author

I think it would be possible to add an impl for &PreEscaped.

this would be nice since it will cover most common case I think

@lambda-fairy
Copy link
Owner

This is fixed by #320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants