如何将计算结果与泛型进行比较?T 总是一些无符号整数类型(u64、u32 等),所以代码片段中的应该可以工作,但是我如何说服 rust 编译器?
fn reproduction<T>(val: T) -> bool
where
T: PartialOrd
{
let var_of_type_integer = 7; // actually the result of a calculation
if val < var_of_type_integer { // ERROR: expected type parameter, found integer
return true;
}
false
}
Run Code Online (Sandbox Code Playgroud)