Does non-matching arm take the owner of a variable in a “match” statement in Rust?
问题 I'm new to Rust. Below is my testing. #[derive(Debug)] enum Food { Cake, Pizza, Salad, } #[derive(Debug)] struct Bag { food: Food } fn main() { let bag = Bag { food: Food::Cake }; match bag.food { Food::Cake => println!("I got cake"), x => println!("I got {:?}", x) } println!("{:?}", bag); } When I run it, I got an error. error[E0382]: borrow of moved value: `bag` --> src\main.rs:20:22 | 17 | x => println!("I got {:?}", x) | - value moved here ... 20 | println!("{:?}", bag); | ^^^ value