Rust uses traits but is pure virtual inheritance still better for some cases?
The functions that accept an object with a specific trait that requires specific function(s) must access the functions of the function-traited object somehow. Is a unique instance of a function that accepts a such an object required for each call of the function that has a unique (different) kind of object that implements the trait as the function arg? (Granted, the compiler could take care of this.)
I.e. with inheritance, a single instance of a function can accept a pure virtual base class argument that will work for any dynamically created instance of an object that inherits the pure virtual base class. Do Rust traits support this.
To further clarify by contrast: In C++, for functions that have a template parameter T and corresponding arg, e.g. some_function<typename T>(T t)
, the compiler generates a unique instance of the function template for each call of some_function
that has a unique T. That's why the function templates are typically implemented in header files. I.e. They are "inlined". However, a function that accepts a base class can be implemented in a source file (i.e. inlining not strictly necessary).
Do functions in Rust that accept an object with a specific trait as an arg, require inlining for use with each unique type that implements the trait (similar to the C++ inlining of function templates for each unique T)?