Hello All. It has been a minute but I am back to trying to learn Rust and am making a small text rpg to help this process. I have noticed that as a Javascript guy, that I have gotten perhaps a little too comfortable with the idea of inheritance and OOP, too comfortable because this does not work with Rust. I do kind of understand that the OOP side of Rust utilizes the "has-a" vs "is-a" relationship, meaning composition. From the reading Ive done, apparently traits are kind of like interfaces for other OO languages, which I have no experience using. Im posting this looking for a bit of direction and advice on how to go about, or the correct way to build with Rust. Being that im working on a small text rpg, I will use "Weapons" as the working example. Currently I have it setup like this:
struct BaseWeapon {
name:String,
weapon_type:WeaponTypes,
damage_type:DamageTypes,
min_damage:u8,
max_damage:u8,
}
enum CommonWeapons {
}
impl Weapon for CommonWeapons {
type BaseWeapon = BaseWeapon;
fn new(name:String,damage_type:DamageTypes,weapon_type:WeaponTypes,min_damage:u8,max_damage:u8) -> Self::BaseWeapon {
BaseWeapon {
name,
damage_type,
weapon_type,
min_damage,
max_damage
}
}
}
trait Weapon{
type BaseWeapon;
fn new(name:String,damage_type:DamageTypes,weapon_type:WeaponTypes,min_damage:u8,max_damage:u8) -> Self::BaseWeapon;
}
enum WeaponTypes {
Common,
Martial,
Exotic
}
enum DamageTypes {
Slashing,
Piercing,
Bludgeoning,
Fire(u8),
Ice(u8),
Magic(u8),
Electric(u8),
}
fn main(){
}
I guess I just want some input or constructive criticism on how to make this better. As of now the enum CommonWeapons variants are kind of unusable which leads me to believe that im probably not doing something the best it can be. Thanks in advance.