Crates.io | dabus |
lib.rs | dabus |
version | 0.5.1 |
source | src |
created_at | 2022-05-26 23:27:12.414634 |
updated_at | 2023-09-20 16:04:31.779556 |
description | Dynamic Aplication Controll Bus - an asynchronous, event based module system for thoes who want to move fast and *not* break things |
homepage | |
repository | https://git.fawkes.io/mtnash/dabus/ |
max_upload_size | |
id | 594587 |
size | 53,613 |
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.
the issue tracker for this project is on the github mirror
DABus
structure does not need to know any of the types related to a handler, or any events it is processinglog
crate, but it is still rather confusing to debug. hopefully this will change soon with backtracesA event handler for DABus
is a simple struct method, something like this:
use dabus::BusInterface;
#[derive(Debug)]
struct ExampleHandler;
impl ExampleHandler {
async fn hello_world(&mut self, arguments: (), mut _interface: BusInterface) {
/*
here, arguments is the args passed to the event call,
and _interface is a struct for communicating with the bus that invoked it
warning! do NOT use BusInterface outside of the async handler it was passed to!
it may seem like a good way of doing things, but IT WILL NOT WORK!!!
*/
println!("Hello, World!");
}
}
and then define the event it goes along with
// the name args return type
dabus::event!(HELLO_EVENT, (), ());
To convert this from a regular struct to an bus stop, implement BusStop
use dabus::{BusStop, EventRegister};
impl BusStop for HelloHandler {
// this function provides a list of the handlers that this stop provides
fn registered_handlers(h: EventRegister<Self>) -> EventRegister<Self> {
// event def event function
h.handler(HELLO_EVENT, Self::hello_world)
}
}
and finally, to use this
use dabus::DABus;
#[tokio::main]
async fn main() {
let mut bus = DABus::new();
// create a new instance of HelloHandler, and pass it to the bus for useage
bus.register(HelloHandler);
// the event arguments (type from event def)
bus.fire(PRINT_EVENT, "Hello, World!".to_string()).await.unwrap();
// you should now see Hello, World! on your terminal!
}
This crate requires nightly!
this is why:
#![feature(downcast_unchecked)]
#![feature(drain_filter)]
#![allow(incomplete_features)]
#![feature(specialization)]
name | description | default behavior |
---|---|---|
backtrace_track_values |
backtraces will include debug-formats of handler arguments and returns | disabled |