I'm trying to insert multiple pieces into a hashmap as so
fn main() {
let mut pieces: HashMap<&str, Piece> = HashMap::new();
for column in b'a'..=b'h' {
let column_char: char = column as char;
let piece_position: String = format!("{}2", column_char);
pieces.insert(piece_position.clone().as_str(), Piece { icon: "1", colour: Colour::White });
}
}
I'm getting the following Errors:
borrowed value does not live long enough
creates a temporary value which is freed while still in use
I believe the error is due to me passing a memory location that is cleared just after the insert. I thought if I cloned piece_positions
pieces would get to own the new copy and the memory of the variable would not be cleared. How would I do this as this is not working?