So, I am currently working on a library, and am looking to make it as idiomatic and clean as possible.
I want to receive events from an outside websocket API, and send them over to my library's users. Currently, I do this by having a single "handler" trait that end users implement, that allows them to override specific event handling functions to their needs. But the internal implementation is a complete mess, and I am not sure if that way of doing things are particularly Rust-y.
In particular, I require the following:
- Mutable borrow to the "dispatcher" (or "client", in my implementation linked below) object, required for sending responses back to the 3rd party API.
- Mutable borrow to "self", to give flexibility to the end users.
- async/.await support (Currently using async-trait for that)
My current implementation is available here
p.s: I might be approaching this from completely the wrong perspective. In that case, please let me know of a better way!