Problem with HashMap contains_key()

Context for the code:

let skipped = HashMap::new();
let mut freefams = 0; 
        let v = &reservations[r#type]; 
        if v > &(0 as u64) && usedtypes.contains_key(r#type){
            freefams += 1; 

I get an error stating "the trait Borrow<&str> is not implemented for &std::string::String" with the line:


For reference, usedtypes is a HashMap with key of type String and value of type String.
Thanks for your time and help.

Can you please double check that the key type is String and not &String. You can do this by adding a type annotation:

let usedtypes: HashMap<String, String> = ...;

Ok that worked for me. I added the type annotation and I was able to use .to_string() to get it to work. Thanks.

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.