you can use ToPrimitive trait from num
example (you can avoid Option with AsPrimitive):
pub struct Point<T> {
pub x: T,
pub y: T,
}
impl<T: Copy + 'static> Point<T> {
pub fn from<U: num::cast::AsPrimitive<T>>(other: Point<U>) -> Point<T> {
Point {
x: other.x.as_(),
y: other.y.as_(),
}
}
}
fn do_stuff() {
let a = Point{x: 0i32, y: 0i32};
let b = Point::<f32>::from(a);
}