The following code:
#![allow(dead_code)]
#[derive(Debug, Clone)]
pub struct SmallFiles {
pub entries: Vec<u8>,
}
#[derive(Debug, Clone)]
pub struct Block {
pub pos: u64,
pub size: usize,
}
#[derive(Debug, Clone)]
pub struct BigFile {
pub blocks: Vec<Block>,
}
#[derive(Debug, Clone)]
pub enum TocEntry {
SmallFiles(SmallFiles),
BigFile(BigFile),
}
#[derive(Debug, Clone)]
pub struct Toc {
pub entries: Vec<TocEntry>,
}
fn main() {
let mut toc = Toc { entries: Vec::new() };
let big_file = BigFile { blocks: Vec::new() };
toc.entries.push(TocEntry::BigFile(big_file));
let block = Block { pos: 0, size: 0 };
match &toc.entries[0] {
TocEntry::BigFile(mut e) => e.blocks.push(block),
_ => {}
}
}
fails to compile with error:
Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of a shared reference
--> src/main.rs:35:11
|
35 | match &toc.entries[0] {
| ^^^^^^^^^^^^^^^
36 | TocEntry::BigFile(mut e) => e.blocks.push(block),
| -----
| |
| data moved here
| move occurs because `e` has type `BigFile`, which does not implement the `Copy` trait
error: aborting due to previous error
I've tried it with "ref mut" in the catch clause and also tried RefCell. But I haven't found a solution which compiles. How can I solve the above issue?