Hi, folks!
I'm trying do this:
fn main() {
let mut indexer_customer = IndexerCustomer::new();
let customer = Customer::new(1, "Martin".to_string(), "New York".to_string());
indexer_customer.insert(customer);
let customer = Customer::new(2, "Johnny".to_string(), "Austin".to_string());
indexer_customer.insert(customer);
}
But I'm getting the error:
error[E0499]: cannot borrow `indexer_customer` as mutable more than once at a time
--> src/main.rs:52:5
|
49 | indexer_customer.insert(customer);
| ---------------- first mutable borrow occurs here
...
52 | indexer_customer.insert(customer);
| ^^^^^^^^^^^^^^^^
| |
| second mutable borrow occurs here
| first borrow later used here
error: aborting due to previous error
I can't understand where the borrow is occurring. I'm not using "&" explicitly.
The method insert
is:
pub fn insert(&'a mut self, customer: Customer) {
let customer_opt = match self.index_code.entry(customer.code) {
Entry::Occupied(_) => None,
Entry::Vacant(e) => Some(&*e.insert(customer)),
};
match customer_opt {
Some(customer) => {
self.index_name.insert(&customer.name, &customer);
self.index_city.insert(&customer.city, &customer);
}
None => {}
}
}
The playground is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=391247b164b5c14c13222aa38a5e9d71
How I can resolve this error in this code?
I appreciate any help! Thank you.