Say*_*osh 2 integer traits rust
我想为 rust 中所有无符号整数类型的通用函数定义特征绑定。函数签名如下:
fn process_unsigned<T: UnsignedInt>(param: T) -> T {
if param meets condition {
// process and return result as T
}
else {
return 0; // has to meet the trait bound on T
}
}
Run Code Online (Sandbox Code Playgroud)
T 的合适界限是多少?
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |