I'm trying to implement a class based format in Rust, which doesn't have classes or object-oriented concepts like inheritance.
Consider the following example:
class Creature {
int id;
bool alive
};
class Human: public Creature {
int salary;
};
class Dog: public Creature {
bool has_fur;
};
If I want to implement the same structure in Rust I would do something like this:
struct Human {
id: i32,
alive: bool,
salary: i32,
}
struct Dog {
id: i32,
alive: bool,
has_fur: bool,
}
Will the duplicated structs make the application require more memory than if they were written in C++ and inherited from a base class (or maybe used prototypes in JavaScript)? The application will hold millions of objects.
I guess it will be a lot of duplicated member names in the code, which is maybe a problem in itself. But how would you translate the data structure in Rust (with the least memory implication as possible)? Or is this the way to go?