DABus
DABus is a multi-type aplication bus. It allows for you to have multiple completely independant "Handlers" or "Bus Stops" that you can interact with and can interact with eachother without aknowlaging eachothers existance. it maintains all of rust's type saftey and guarentees, while being able to act in a highly dynamic fasion, almost like something out of javascript, but with none of the downsides.
Key Features
- Type-Erased: the central
DABus
structure does not need to know any of the types related to a handler, or any events it is processing - Asynchronous: all handlers are async
- Thread-Safe: multithreaded async executers are fully supported
- Type-Safe: handlers and event calls are fully statically typed
- Convenient: API does not force you to go through inconvenient loopholes
Limitations
- As preivously mentioned, it is asynchronous and thread-safe. unfortunatally, there is no way around this, as all types must be Sync and Send, and async is a core requirement of how the executor functions
- Because of all of the dynamic typing used internally, this relies heavliy on dynamic dispatch and thus suffers from its performance issues (dont worry, its not slow)
- For debugging, this implements logging using the
log
crate, but it is still rather confusing to debug. hopefully this will change soon with backtraces
Usage
A event handler for DABus
is a simple struct method, something like this:
use BusInterface;
;
and then define the event it goes along with
// the name args return type
event!;
To convert this from a regular struct to an bus stop, implement BusStop
use ;
and finally, to use this
use DABus;
async
Important Note
This crate requires nightly!
this is why:
Crate Features
name | description | default behavior |
---|---|---|
backtrace_track_values |
backtraces will include debug-formats of handler arguments and returns | disabled |
TODO's
- docs
- tests
- backtraces (do LATER, do logging NOW)
- format backtraces
- a way of turning off backtraces? (performance)
- examples IMPORTANT
- proper error handling
- multi-handler events
- more complex event matching (allow handlers to consume an event, after looking at the arguments?)
- nested handler calls
- error forwarding
- take a look at rust api guidelines
- profiling and optimization