What's the Rust way of doing what I would have done with inheritance to capture events in cursive?

Viewed 183

I'm looking for a practical answer here, I understand Rust approach to OOP, composition over inheritance, writing traits to reuse code and all that jazz.... which is all fine if I had full control of the code and I could have chosen to write everything accordingly, but I'm stuck with the following scenario:

I'm trying to use cursive's TableView, which implements the View trait, and therefore its method on_event. I want to handle more events that those that come with the TableView implementation, but I want everything else, including the events that TableView already handles, to remain the same.

Since I've done OOP for the best part of 25 years, the natural thing for me to do is to extend TableView, implement on_event and call super.on_event where I see fit. This is not possible in Rust, as far as I understand.

I could have my own MyTable struct, which contains a TableView struct, implement the View trait on MyTable, and for every method just call the same method in TableView. I reject this as the proper solution, it can't be...

What's the closest I can get to OOPs super paradigm, or alternative, what is the Rust way of doing this without having to write a lot of useless code that just proxies calls to an inner struct of the type that I'm trying to extend?

Edit: For more detail on exactly what I want to accomplish please check this other question.

0 Answers
Related