bus-contract
Traits and types for an in-process bus of hook points (requests, events, alter, collect) with ordered listeners.
A library declares its points and listeners against the Bus trait.
The application creates the bus and passes it to each library at
construction. There is no global.
Contents
- Points are types (
Point): an id (doc.close), the input every listener reads, the value a listener edits, and a declared kind (request,event,alter,collect). Bus, an object-safe trait (Arc<dyn Bus>): declare a point; listen under an id and an owner, ordered byafter/before/last, then priority; unlisten; forget an owner;alterandcollectemits that return every listener's failure (error, panic, missed deadline); failure sinks; introspection.- Typed calls on
dyn Bus(declare::<P>,listen::<P>,alter::<P>,collect::<P>,on_failure), written once over the erased methods: an implementation writes only those. - A contract table (
PointDecl): a library's points as aconst, readable before anything is built, declared withdeclare_all. - Tools on the contract:
order_dump("who runs when", for reviewed files and debug views) andmissing_targets(an ordering constraint naming a listener that is not there). - No dependencies, no
unsafe, no async runtime.
This crate has no implementation. One is Kernel in
egui-pop-hooks. The
guarantees an implementation must keep are documented on Bus.
Example
use Arc;
use ;
/// The library's request: a document closes.
;
/// The library's points, readable before anything is built.
pub const POINTS: & = &;
/// The library takes the bus; it never constructs one.
;
The application creates the bus and passes it to each library:
let bus: = new; // or its own
let docs = new;
let search = new;
print!;
Not included
- A journal (events with a revision, catch-up from a revision).
- Transport across processes.
License
MIT OR Apache-2.0, at your option.