Ich habe Probleme herauszufinden, wie man eine HashMap mit einem Schlüssel des Typs ~str
idiomatisch verwendet. Zum BeispielString-keyed HashMap in Rost?
let mut map: hashmap::HashMap<~str, int> = hashmap::HashMap::new();
// Inserting is fine, I just have to copy the string.
map.insert("hello".to_str(), 1);
// If I look something up, do I really need to copy the string?
// This works:
map.contains_key(&"hello".to_str());
// This doesn't: as expected, I get
// error: mismatched types: expected `&~str` but found `&'static str` (expected &-ptr but found &'static str)
map.contains_key("hello");
Basierend auf this Bug-Report habe ich versucht,
map.contains_key_equiv("hello");
bekam aber
error: mismatched types: expected `&<V367>` but found `&'static str` (expected &-ptr but found &'static str)
Ich weiß nicht wirklich, diese letzte Nachricht verstehen; Hat jemand einen Vorschlag?