&str and string are "equivalent", so use the _equiv version of functions you need. I'll send a patch to better-document this common use case later today. On 2014-06-06 9:40 AM, "Diggory Hardy" <li...@dhardy.name> wrote:
> 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 > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev > >
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev