[rust-dev] strings in sets/maps

Diggory Hardy lists at dhardy.name
Fri Jun 6 08:34:26 PDT 2014


contains_equiv — thanks

Related: how to do this in a match?

let s = "abc".to_owned();
match s {
	"abc" => ...


On Friday 06 Jun 2014 09:42:32 you wrote:
> &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" <lists at 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() ) );
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140606/6c1ba17d/attachment.html>


More information about the Rust-dev mailing list