Well, I eventually figured out how to get things compiling, but it was
highly non-obvious. I would appreciate it if someone could shed some light
on why things behave this way so that I may learn to visually "see" the
error.
Say we have the following struct
pub struct Vector3<T> {
priv mut m_v: [T * 3]
}
1. The following fails because it says it can't find <T> in the second line.
pub pure fn foo<T : Zero>() -> Vector3<T> {
Vector3<T> { mut m_v: [Zero::zero(), Zero::zero(), Zero::zero()] }
}
Changing it to
pub pure fn foo<T : Zero>() -> Vector3<T> {
Vector3 { mut m_v: [Zero::zero(), Zero::zero(), Zero::zero()] }
}
works. I had compared against core::DVec to avoid strange errors, but I
seemed to have overlooked the lack of type in the constructor there. Why
is the redundant inclusion of <T> bad? If anything it would allow the
compiler to point out an error if the types didn't come out to be as
intended.
2. Most of my other issues were multiple cases of this error. The following
invocation of the function above fails with "unresolved name: int"
let v = foo<int>();
Removing the explicit type specialization works, but requires an explicit
type declaration to be unambiguous.
let v : Vector3<int> = foo();
Why could I not be specific with the type parameter to the function? Is
there an alternative meaning with which it clashed?
Ashish
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev