Hi,
I'm learning Rust and find it very interesting. My background is mostly
python and C++. I'm now trying to get my head round the Rust generic system
and was wondering whether there' s something equivalent to typedef in Rust?
my use case is:
- I have a generic 2d vector struct : struct Vec2x<T> {x:T, y:T}
- I would like to declare somethere in my code how to specialise this
struct. I'm not sure yet whether it's going to be float or f64. So to avoid
having to update float to f64 everywhere in the code, I was hoping I could
write that:
type Vec2f = Vec2x<float>
and then use Vec2f without worrying whether it's float or f64.
it seems to compile compiles, but the following did not work:
let v = Vec2df:new(1.0, 2.0);
I must have misunderstood how to use "type".
here's the full code:
pub mod math {
#[deriving(Eq, Clone)]
struct Vec2x<T> { x:T, y:T }
impl<T> Vec2x<T> {
pub fn new(a:T, b:T) -> Vec2x<T> { Vec2x{x:a, y:b} }
}
}
#[test]
fn test_Vec2x() {
// let v = math::Vec2x::new(1f, 2f);
type Vec2f = math::Vec2x<float>;
let v2 = Vec2f::new(1f, 2f); // does not compile
}
cheers,
Rémi
--
Rémi Fontan : [email protected]
mobile: +64 21 855 351
93 Otaki Street, Miramar 6022
Wellington, New Zealand
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev