-
-
Notifications
You must be signed in to change notification settings - Fork 22
Feature: Primary vs secondary inheritance #85
Copy link
Copy link
Open
Description
// We should try to see if its feasible to allow
pub struct Throwable {
health: i32,
}
pub struct Enemy {
health: i32,
}
#[inherit(Primary(Throwable), Secondaries([Enemy, ...]))]
pub struct Turtle {
}
impl Turtle {
pub fn new() -> Self {
Self {
health: 100,
}
}
fn damage(&mut self, amount: i32) {
self.health -= amount; // We can assume this is the health from Throwable, as it's the primary parent.
println!("Turtle took {} damage, health is now {}", amount, self.health);
}
}
/// As opposed to no primary, where we would have to specify which health we are referring to (Throwable or Enemy), we can directly access it here without ambiguity.
pub struct Throwable {
health: i32,
}
pub struct Enemy {
health: i32,
}
#[inherit(Throwable, Enemy)]
pub struct Turtle {
}
impl Turtle {
pub fn new() -> Self {
Self {
health: 100,
}
}
fn damage(&mut self, amount: i32) {
self.throwable.health -= amount; // We can assume this is the health from Throwable, as it's the primary parent.
println!("Turtle took {} damage, health is now {}", amount, self.throwable.health);
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels