On 30/11/13 10:33, Ashish Myles wrote:
Previously we had the Copy trait, which when implemented by trait T allowed one to write [Zero::zero(), ..SZ] where T implemented the Zero trait. But now I am not sure how to get that behavior. Concretely, here is the code I want to get compiling. (Just to check, I added both Clone and DeepClone, even though they don't automatically allow implicit copyability).---- use std::num::Zero; enum Constants { SZ = 2 } struct Foo<T>([T, ..SZ]); impl<T : Clone + DeepClone + Zero> Foo<T> { pub fn new() -> Foo<T> { Foo([Zero::zero(), ..SZ]) } } ---- The error I get is: error: copying a value of non-copyable type `T` tmp.rs:155 Foo([Zero::zero(), ..SZ]) Any way to do this? Or is this no longer supported for general types? Any intentions to add this behavior again? Otherwise, I can't even initialize my struct while being agnostic to the specific value of SZ. Ashish _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
Initialising a fixed size vector [T, ..n] by [foo(), .. n] unfortunately requires that `T` is implicitly copyable (that is, it doesn't move ownership when passed by value), and there's no way around this other than [foo(), foo(), foo(),...].
Huon _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
