刚摆完界面,写一段rust调剂一下
作者:互联网
可怜的界面排版工人,刚摆完界面,感觉好枯燥,写一点Rust调剂一下哦, 我就是喜欢贴在博客里,方便我以后看。
fn max(arg: &[int]) -> int {
let mut x = arg[0];
for val in arg.iter() {
if *val > x {x = *val}
}
x
}
fn main() {
let x = [1, 2, 3, 4, 5, 2, 4, 5, 8, 10, 0];
let max2 = |arg: &[int]| -> int {
let mut x = arg[0];
for val in arg.iter() {
if *val > x {x = *val}
}
x
};
let mut num = max(x);
println!("num = {}", num);
num = max2(x);
println!("num = {}", num);
}
标签:mut,界面,val,int,调剂,num,let,arg,rust 来源: https://blog.51cto.com/huanghongqiao/2748943