I am trying to implement a constant value of generic type, but the compiler can't figure out the type (Error: cannot find type T in this scope).
use num::Float
pub const R: T = T::from(8314.4621).unwrap();
fn main() {
println!("{:?}", foo(3.0_f64))
}
pub fn foo<T: Float>(a: T) -> T {
a * R
}
- How should I declare the implemented traits for
Tlike theFloattrait of thenumcrate? - Furthermore, is there any easier way to declare the value instead of this verbose way
T::from(8314.4621).unwrap()? - Just to be sure, is this solved in compile or run time?