Given this code-snippet:
pub fn verse(start_bottles: i32) -> String {
let mut song_template: String = "%1 of beer on the wall, %2 of beer.\n%3, %4 of beer on the wall.\n".to_string();
match start_bottles {
0 => lyrics_no_bottles(&mut song_template),
1 => lyrics_one_bottle(&mut song_template),
2 => lyrics_two_bottles(&mut song_template),
_ => lyrics_more_bottles(&mut song_template, start_bottles)
}
song_template
}
pub fn sing(first: i32, last: i32) -> String {
let mut song: String = "".to_string();
for num in (8..6).rev() {
song = verse(1);
}
song
}
As I output verse(1) it works fine - the tested string appears and is complete. But when I assign the result of verse(1) to the String binding song, song seems to be empty? I do not understand this behaviour.
Stringtype annotations, when your right-hand-side already is a string (which it is in case of usingto_string()).