我正在尝试提取.tar.bz文件(或.tar.whatever),并且还能够获得xx%进度报告.到目前为止我有这个:
pub fn extract_file_with_progress<P: AsRef<Path>>(&self, path: P) -> Result<()> {
let path = path.as_ref();
let size = fs::metadata(path)?;
let mut f = File::open(path)?;
let decoder = BzDecoder::new(&f);
let mut archive = Archive::new(decoder);
for entry in archive.entries()? {
entry?.unpack_in(".")?;
let pos = f.seek(SeekFrom::Current(0))?;
}
Ok(())
}
Run Code Online (Sandbox Code Playgroud)
想法是用来pos/size获得百分比,但编译上面的函数会让我错误cannot borrow f as mutable because it is also borrowed as immutable.我理解错误的含义,但我并没有真正使用它f作为可变的; 我只使用搜索功能来获取当前位置.
有没有办法解决这个问题,要么强制编译器忽略可变借用,要么以某种不可变的方式获取位置?