在这个琐碎的程序中,我尝试调用i32.max(i32)
fn main() {
let a: i32 = 0;
let b: i32 = 1;
let c: i32 = a.max(b); // <-- Error here
println!("{}", c);
}但是我得到了一个神秘的编译时错误:
error: no method named `max` found for type `i32` in the current scope
--> prog.rs:4:17
|
4 | let c: i32 = a.max(b);
| ^^^
|
= note: the method `max` exists but the following
trait bounds were not satisfied: `i32 : std::iter::Iterator`这一切为什么要发生?我用的是铁锈1.17.0。
如果我使用浮点值,则此示例有效:
let a: f32 = 0.0;
let b: f32 = 1.0;
let c: f32 = a.max(b);这使事情变得更加神秘。
发布于 2017-11-06 07:09:31
发布于 2017-11-06 06:23:56
如果你想比较数字,你可以这样做:
use std::cmp;
fn main() {
let a: i32 = 0;
let b: i32 = 1;
let c: i32 = cmp::max(a, b);
println!("{}", c);
}https://stackoverflow.com/questions/47130574
复制相似问题