pub struct DispatchTable { /* private fields */ }Expand description
Named command registry with synchronous dispatch.
Implementations§
Source§impl DispatchTable
impl DispatchTable
Sourcepub fn register<F>(&self, name: impl Into<String>, handler: F)
pub fn register<F>(&self, name: impl Into<String>, handler: F)
Register a handler for a command name.
If a handler was already registered under name it is replaced.
Sourcepub fn register_simple<F>(&self, name: impl Into<String>, handler: F)
pub fn register_simple<F>(&self, name: impl Into<String>, handler: F)
Register a handler that takes no payload.
The incoming payload bytes are silently discarded.
Sourcepub fn dispatch(
&self,
name: &str,
payload: Vec<u8>,
) -> Result<Vec<u8>, ConduitError>
pub fn dispatch( &self, name: &str, payload: Vec<u8>, ) -> Result<Vec<u8>, ConduitError>
Dispatch a command by name.
Returns the handler’s response bytes on success, or
ConduitError::UnknownCommand if no handler is registered for name.
Sourcepub fn dispatch_or_error_bytes(&self, name: &str, payload: Vec<u8>) -> Vec<u8> ⓘ
pub fn dispatch_or_error_bytes(&self, name: &str, payload: Vec<u8>) -> Vec<u8> ⓘ
Dispatch a command by name, returning raw bytes in all cases.
On success the handler’s response bytes are returned. On failure the
error’s Display text is returned as UTF-8 bytes. This is a
convenience wrapper for call sites (such as the custom protocol
handler) that must always produce a Vec<u8>.
Trait Implementations§
Source§impl Debug for DispatchTable
impl Debug for DispatchTable
Auto Trait Implementations§
impl !Freeze for DispatchTable
impl RefUnwindSafe for DispatchTable
impl Send for DispatchTable
impl Sync for DispatchTable
impl Unpin for DispatchTable
impl UnsafeUnpin for DispatchTable
impl UnwindSafe for DispatchTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more