The type
keyword has one limitation:
type Vec2f = Vec2<f64>;
struct Vec2<T> {
x: T,
y: T,
}
impl<T: Num> Vec2<T> {
fn new(x: T, y: T) -> Vec2<T> {
Vec2 { x: x, y: y }
}
}
fn main() {
// This is what I would like to do, but it doesn't work:
let p = Vec2f::new(0.0, 0.0);
// This works, but referring to the original name is what I wanted to avoid in
// the first place.
let p: Vec2f = Vec2::new(0.0, 0.0);
}
All that’s needed here is the type def expanding to Vec2::<f64>
when applicable. Or maybe this is just another reason to remove ::
as disambiguation.