Single inheritance is just about the only thing I miss from C++. I am no Rust expert, but seems it needs two things: able to have one struct extend another, and able to have casting ability (automatic upcasts, and explicit downcasts).
Currently I have the horrible hack (I know it’s terrible):
#[repr(C, packed)]
struct Monster<T> {
x : i32,
y : i32,
hitpoints : i32,
extra_data : T
}
#[repr(C, packed)]
struct Demon {
fireballs : i32,
}
Then we create Monster<Demon>
and access its data. Casting up and down seems to work, but maybe I am just lucky and the language never meant this. What seems to be needed is something like:
struct Monster {
x : i32,
y : i32,
hitpoints : i32
}
struct Demon : Monster {
fireballs : i32
}
Would be helpful if a function accepting &Monster
would also accept &Demon
. And adding a forced downcast may be possible, if often evil. Again I am no Rust expert so I don’t know any of the more thorny issues, I will just use my hacked generics method until there is a better option.
Steve