为什么在可变函数的论证中不允许借用

时间:2018-05-31 09:44:28

标签: rust ownership borrowing

标题可能有点令人困惑,我的意思是当我尝试编译时:

if folder_file_paths.len() > compressed_data.len() {
    compressed_data.reserve(folder_file_paths.len() - compressed_data.len() );
}

我收到此错误:

error[E0502]: cannot borrow `compressed_data` as immutable because it is also borrowed as mutable
   --> src/ImageMatching/main.rs:33:59
   |
33 |         compressed_data.reserve(folder_file_paths.len() - compressed_data.len() );
   |         ---------------                                   ^^^^^^^^^^^^^^^       - mutable borrow ends here
   |         |                                                 |
   |         mutable borrow occurs here                        immutable borrow occurs here

但我无法想出这是一个问题的原因,因为不应该首先处理参数,复制生成的usize值,然后复制reserve功能运行?

在实际函数开始执行后,计算函数的参数是什么时候?

修改:folder_file_pathVeccompressed_dataHashMap

0 个答案:

没有答案