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

move occurs because item1.list2 has type Vec<Box<dyn MyTrait + Send>>, which does not implement the Copy trait #494

Closed
bbigras opened this issue Jun 11, 2021 · 5 comments · Fixed by #500

Comments

@bbigras
Copy link

bbigras commented Jun 11, 2021

I got this error with main but not with 0.10.5.

error[E0507]: cannot move out of `item1.list2` which is behind a shared reference
 --> src/main.rs:3:10
  |
3 | #[derive(Template)]
  |          ^^^^^^^^ move occurs because `item1.list2` has type `Vec<Box<dyn MyTrait + Send>>`, which does not implement the `Copy` trait
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Cargo.toml

[dependencies]

# works
askama = "0.10.5"

# doesn't work
askama = { git = "https://github.com/djc/askama.git", branch = "main" }

main.rs

use askama::Template;

#[derive(Template)]
#[template(path = "template.txt")]
struct MyStruct1 {
    list1: Vec<MyStruct2>,
}

struct MyStruct2 {
    list2: Vec<Box<dyn MyTrait + Send>>,
}

pub trait MyTrait {
    fn render(&self) -> String;
}

fn main() {}

template.txt

{% for item1 in list1 %}
{% for item2 in item1.list2 %}
{% endfor %}
{% endfor %}

Feel free to rename the issue.

@vallentin
Copy link
Collaborator

As a workaround, it should work if you change item1.list2 to item1.list2.iter(). However, I'll look into why that fails, as right now I don't recall the reason why it would fail.

@djc
Copy link
Owner

djc commented Jun 14, 2021

@vallentin would be great if you can look into this, thanks!

@vallentin
Copy link
Collaborator

@djc I will. I've just been a bit busy the past week and this week, but I've added it to my todo :)

@bbigras
Copy link
Author

bbigras commented Jun 14, 2021

As a workaround, it should work if you change item1.list2 to item1.list2.iter().

It works. Thanks :)

@djc
Copy link
Owner

djc commented Jun 23, 2021

Fixed in #500.

@djc djc closed this as completed Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants