Should be trivial, but can't see how to solve this borrow checker error

I'm quite ashamed because I can't solve this:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c16d3ec2dbf625cf5299b2e25699d17b

I think as_mut was what I need, but it gives me &mut &Data the 2nd & being the issue I believe, but how to get out of this situation?

Thanks for any help :slight_smile:

You would want to use get_mut instead of get. Additionally this requires you to make the lock mutable:

fn main() {    
    let mut all_data = DATA_TABLE.lock().unwrap();
    match all_data.get_mut(&0u64) {
        Some(data) => data.hash.clear(),
        None => (),
    }
}
2 Likes

Use get_mut instead of get :slight_smile:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d96101c212f82a30230bed40e82d9b3c

Edit: simultaneous answer :smiley:

2 Likes

Thanks to both of you, it was trivial indeed, but I was searching in Option doc and didn't though of looking in HashMap one… ^^' /ashamed

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.