小编Web*_*ogz的帖子

不能将`*x`借用为可变因为它也被借用为不可变的

我正在制作一个组合优化项目来学习Rust,我遇到了一个问题,我无法解决自己...

我有两个功能:

pub fn get_pareto_front_offline<'a>(scheduling_jobs: &'a Vec<Vec<u32>>, costs_vector: &'a Vec<(u32, u32)>) -> Vec<(&'a Vec<u32>, &'a (u32, u32))> {
    // ...
}
Run Code Online (Sandbox Code Playgroud)

pub fn pareto_approach_offline<'a>(list_of_jobs: &'a mut Vec<Vec<u32>>, neighborhood: &'a mut Vec<Vec<u32>>, costs: &'a Vec<(u32, u32)>) -> Vec<(&'a Vec<u32>, &'a (u32, u32))> {
    let pareto_front = get_pareto_front_offline(neighborhood, costs);

    loop {
        if pareto_front == vec![] {
            break;
        }

        neighborhood.clear();

        for front in pareto_front.iter() {
            neighborhood.push((front.0).clone());
        }
    }

    pareto_front
}
Run Code Online (Sandbox Code Playgroud)

我有一个问题,因为编译器告诉我:

cannot borrow '*neighborhood' as mutable because it is also borrowed as …
Run Code Online (Sandbox Code Playgroud)

mutable immutability rust borrowing

2
推荐指数
2
解决办法
1636
查看次数

标签 统计

borrowing ×1

immutability ×1

mutable ×1

rust ×1