Dear List,

I want to use strings as map keys, but couldn't find any mention of this in my 
understanding common use-case. The following works but as far as I understand 
requires a copy of the potential key to be made to call `contains()`, is this 
correct?

    let mut set: HashSet<String> = HashSet::new();
    set.insert( "x".into_string() );
    println!( "set contains x: {}", set.contains( &"x".into_string() ) );

Note: I would normally be storing/testing &str types with non-static lifetime, 
but I don't 
think this makes a difference.

I notice that HashSet<&str> also works (if lifetimes of the inserted strings 
are 
sufficient).

Regards,
Diggory Hardy
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to