consider making `Import` implement `Copy`
Opened this issue · 1 comments
cameronbraid commented
To use an import multiple times you have to manually clone it :
let map = rust::import("std::collections", "HashMap");
let tokens: rust::Tokens = quote! {
fn test() {
let mut m = $(map.clone())::new();
m.insert(1u32, 2u32);
let mut m2 = $(map.clone())::new();
m2.insert(1u32, 2u32);
}
};
Otherwise without the clone :
let map = rust::import("std::collections", "HashMap");
let tokens: rust::Tokens = quote! {
fn test() {
let mut m = $map::new();
m.insert(1u32, 2u32);
let mut m2 = $map::new();
m2.insert(1u32, 2u32);
}
};
you get error :
20 | let map = rust::import("std::collections", "HashMap");
| --- move occurs because `map` has type `genco::lang::rust::Import`, which does not implement the `Copy` trait
...
24 | let mut m = $map::new();
| --- value moved here
25 | m.insert(1u32, 2u32);
26 | let mut m2 = $map::new();
| ^^^ value used here after move
udoprog commented
Makes sense, but probably use some form of implicit cloning since rust::import
could produce a value which is heap allocated.
Thanks for the suggestion!