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

source

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)

source

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 in BusInterface::fire

Trait Implementations§

source§

impl Debug for BusInterface

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsAny for Twhere T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

fn mut_any(&mut self) -> &mut (dyn Any + 'static)

source§

fn to_any(self: Box<T, Global>) -> Box<dyn Any, Global>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynDebug for T

source§

default fn as_dbg(&self) -> &dyn Debug

source§

impl<T> DynDebug for Twhere T: Debug,

source§

fn as_dbg(&self) -> &dyn Debug

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> PossiblyClone for T

source§

default fn is_clone(&self) -> bool

check if Self is infact Clone
source§

default fn try_clone(&self) -> T

attempt to clone Self Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> TypeNamed for Twhere T: Any + 'static,

source§

fn type_name(&self) -> &'static str

gets the type name of Self