Could we have a trait over what the
as cast does, maybe?
I want to write
fn foo<FP: From<f64>+..>(...) -> FP with
f64 implementations, however
f32 does not implement
From<f64>. I don’t care if there is some loss of precision (actually, this is expected), and want to be able to write
f64 constants and use other functions with only
There are two obvious ways Rust could support this:
impl From<f64> for f32— which goes against the trend of not allowing lossy conversions, but I think usually this is not a problem since lower precision is expected with
f32and the range is still huge with explicit +/-inf.
- A new trait for lossy conversions
Of course I can roll my own trait if this doesn’t deserve a common solution, but may be worth discussing (especially the first suggestion).