Skip to content

String keys in HashMap are practically impossible #6095

Closed
@Aatch

Description

@Aatch
type StringMap<T> = HashMap<~str, T>; //Fairly common

fn foo(map:&mut StringMap<uint>) {
  map.insert("Test".to_str(), 1); // This works fine, copying the string isn't unexpected
  map.find("Test"); //Nope. its a &'static str, not a ~str, so the types don't match, the only work around is copying the string
}

Copying the string in order to do a lookup is plain ridiculous. It adds significant overhead where it isn't needed. Now, I'm not sure how to fix it, but this is a common enough case that it should be dealt with.

Related to #3284 - probably.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions