I am struggling to understand the principles behind borrowing while creating a simple program. This is what I have
pub struct GameBoard {
p1_icon: String,
p2_icon: String,
current_player: i8,
}
impl GameBoard {
pub fn prompt_turn(&self) {
let misc = String::from("?");
let icon = match self.current_player {
1 => &self.p1_icon,
2 => &self.p2_icon,
_ => &misc,
};
println!(
"It is Player {}'s turn to go. Please pick your next move to drop a {}",
self.current_player, icon
);
println!("This is a test: {}", self.p1_icon)
}
}
My primary question here is, why does Rust require me to borrow with &self.p1_icon within the match call, but not when I call println?
My next question is, I am having challenges working with string literals in Rust. In my case, there are some strings that are meant to be dynamic—thus why I use Strings—but there are others that are just hard-coded (see misc).
It feels a bit overkill to create a String, then borrow from said String, so I can satisfy the constraints that "match values must all be &String". Is this really how Rust expects developers to code this way, or am I missing something?