Regular float literals do not work:
extern crate num_traits;
use num_traits::float::Float;
fn scale_float<T: Float>(x: T) -> T {
x * 0.54
}
fn main() {
let a: f64 = scale_float(1.23);
}
error[E0308]: mismatched types
--> src/main.rs:6:9
|
6 | x * 0.54
| ^^^^ expected type parameter, found floating-point variable
|
= note: expected type `T`
found type `{float}`
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…