Struct dabus::BusInterface
source · pub struct BusInterface { /* private fields */ }
Expand description
Provides a limited DABus
like api for handler implementations.
This is passed to handlers, giving them a way of running actions on the bus that they are being run from.
Implementations§
source§impl BusInterface
impl BusInterface
sourcepub async fn fire<Tag: Unique, At: DynDebug + Sync + Send + 'static, Rt: DynDebug + Sync + Send + 'static>(
&mut self,
def: &'static EventDef<Tag, At, Rt>,
args: At
) -> Result<Rt, CallTrace>
pub async fn fire<Tag: Unique, At: DynDebug + Sync + Send + 'static, Rt: DynDebug + Sync + Send + 'static>( &mut self, def: &'static EventDef<Tag, At, Rt>, args: At ) -> Result<Rt, CallTrace>
Fires an event on the bus, running appropreate handlers and returning the result.
This function is similar to DABus::fire
in the sense that from the outside, it behaves the same
however internally it does not. see the Notes
section for more details
Returns
on success, this returns the return value sent by the handler, as well as a call trace (this will change)
on failure, this returns only the call trace, which can be used to find what went wrong
Panics
if a handler that is called panics (or the runtime is broken)
Errors
if there is some (expected) error with the runtime. currently this only includes not finding an appropreate handler
Notes
like all functions on this struct, this does not execute an event iself but rather forwards it to the current runtime. this means that if useing this after the scope of the handler it was given to has ended should be considered Undefined Behavior (eventually there will be some safeguard to fix this)
sourcepub async fn fwd_bus_err(&self, error: CallTrace) -> !
pub async fn fwd_bus_err(&self, error: CallTrace) -> !
takes a error (from a nested call, presumablely) and forwards it to the caller of the current event (via the runtime and a deal with the devil)
this is a easy way to handle errors, as it will forward the error, and can produce nice backtraces
Panics
it shouldent, unless something is horribly wrong with the library
Footguns
-
this function (from the perspective of the handler) will never return, but from the persepective of the program it will, so keep that in mind.
-
see the
Notes
section inBusInterface::fire