In C++, an overridden virtual member function can call the version defined in its base class:
struct foo {
virtual void run() {
printf("printf yeah!\n");
}
};
struct bar : foo {
void run() {
foo::run();
std::cout << "un-cout-h!" << std::endl;
}
};
I want to do something similar in Rust. I have a trait containing default method definitions, and I want to reuse those definitions in impls where those methods are overridden:
trait Foo {
fn run(&self) {
// do something
}
}
impl Foo for Bar {
fn run(&self) {
// call default implementation of Foo::run()
// run custom logic
}
}
How do I do this?
Edit: The proposed solution isn't completely satisfactory. Once I override a method, I intend the overridden implementation not to be usable by third parties.