Using non-copyable type in for loop


Hey guys here’s the situation, I’m using to add some templating to an Iron project.

I have a vector of strings that contain error messages to render to the template. I want to loop the errors and insert them in to a map using the build in map builder. Consider the following code:

template_data.insert_map("errors", |builder| {

            for error in &mut errors {

                builder.insert_str("error", error);




This of course generate said error:

src\ 108:24 error: use of moved value: `builder` [E0382]
src\                 builder.insert_str("error", error);
src\ 108:24 help: run `rustc --explain E0382` to see a detailed explanation
note: `builder` was previously moved here because it has type `mustache::builder::MapBuilder`, which is non-copyable
src\ 112:20 error: use of moved value: `builder` [E0382]
src\             builder

Any help would be appreciated, I’ve been searching for hours with no luck.


Does this work?

    template_data.insert_map("errors", |mut builder| {
            for error in &mut errors {
                builder = builder.insert_str("error", error);


It sure does, thanks x1million!