通过借款参考为不借款

时间:2019-07-15 05:49:58

标签: rust

fn count_occur(v: &Vec<i32>, val: i32) -> usize {
    0
}

fn main() -> () {
    let v1 = vec![1, 2, 3, 4, 5, 6];
    for &item in &v1 {
        let v2 = count_occur(&v1, item);
        println!("{}", v2);
    }
}

item是不可更改的借用参考。为什么编译器接受该代码?毕竟,count_occur接受借用对i32的引用吗?

0 个答案:

没有答案