Is it possible to convert two &str
to a &(String, String)
?
I specifically have a HashMap
that has the tuple (String, String)
as key, and I would like to lookup the map without cloning the &str
.
Consider the following code:
use std::collections::HashMap;
fn main() {
let mut map = HashMap::new();
map.insert(("Hello".to_owned(), "World".to_owned()), 42);
println!("{:?}", get("Hello", "World", &map));
}
fn get<'a>(id_1: &str, id_2: &str, map: &'a HashMap<(String, String), i32>) -> Option<&'a i32> {
// Do this without cloning/to_string
let key: &(String, String) = &(id_1.to_string(), id_2.to_string());
map.get(key)
}