我怎样才能简化这段代码?在面向对象编程之后,我仍然无法理解 Rust 的特征和结构。
struct Player {
entity: Entity,
hp: i32,
atk: i32
}
struct Chest {
entity: Entity,
amount: i32
}
impl Drawable for Chest {
fn draw(&self, mut pencil: Pencil) {
pencil.draw(&self.entity);
}
}
impl Drawable for Player {
fn draw(&self, mut pencil: Pencil) {
pencil.draw(&self.entity);
}
}
Run Code Online (Sandbox Code Playgroud)
也许有一种方法可以像 OOP 中那样继承某些字段?
另外,如果有人知道有关 Rust 特征和结构的良好而清晰的教程,如果您分享它,我将非常高兴!