Hi,
I have just moved some of my code from 0.6 to rust 0.8 and was surprisingly
not too difficult, great!
however I noticed while converting copy to clone that I have to use a lot
of explicit calls to ".clone()" in my templated code. In non templated
code, the compiler is apparently more forgiving.
Here' s a simple example to illustrate my point. Do you understand why I
must write the initialisation of the list as "data:[a.clone(), a.clone(),
a.clone()] " in the templated code and not simply "data:[a, a, a]". As T
implements the clone trait, I was hoping the compiler would automatically
clone when required.
struct mystruct {
data : [float, ..3]
}
impl mystruct {
pub fn new(a:float) -> mystruct {
mystruct{ data:[a, a, a] }
}
}
struct mytmplstruct<T> {
data : [T, ..3]
}
impl<T:Real+Clone> mytmplstruct<T> {
pub fn new(a:T) -> mytmplstruct<T> {
mytmplstruct{ data:[a.clone(), a.clone(), a.clone()] }
}
}
#[test]
fn test_structs() {
let m1 = mystruct::new(1.234f);
let m2 = mytmplstruct::new(1.234f);
}
cheers,
Rémi
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev