1. Urcite bych pouzil &'static str - v tomhle pripade jde o ergonomii a stejne s tim nic extra nedelas.
2. print_data() je pomerne neobvykly zpusob vypsani obsahu, tady je to rozhodne vhodnejsi resit nejakym traitem (formatovani je otazka), treba:
use std::fmt;
struct Animal {
name: &'static str,
sound: &'static str,
}
impl fmt::Display for Animal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Name: {}, Sound: {}", self.name, self.sound)
}
}
fn main() {
let cat = Animal {
name: "Cat",
sound: "Mňau!",
};
println!("{}", cat);
}