[rust-dev] strings in sets/maps

Diggory Hardy lists at dhardy.name
Fri Jun 6 06:40:14 PDT 2014

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 

Diggory Hardy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140606/4d6e5299/attachment.html>

More information about the Rust-dev mailing list