I would like a function that returns f32 if the input is f32, for all other numeric inputs it should return f64.
A simplified example of the structure is this:
use num::{Num, NumCast, ToPrimitive, traits::Float};
fn example<N: Num + ToPrimitive, T: Float>(input: N) -> T {
let output = input + N::one();
NumCast::from(output).unwrap()
}
fn main() {
println!("{}", example::<f32, f32>(1f32));
println!("{}", example::<u32, f64>(1u32));
}
is there a way to control the dispatch so that I can drop the turbofish and it will automatically map
f32 -> f32 and
anything else -> f64 ?