pub struct Router { /* private fields */ }Expand description
Named command registry with synchronous dispatch.
Implementations§
Source§impl Router
impl Router
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 call(&self, name: &str, payload: Vec<u8>) -> Result<Vec<u8>, Error>
pub fn call(&self, name: &str, payload: Vec<u8>) -> Result<Vec<u8>, Error>
Dispatch a command by name.
Returns the handler’s response bytes on success, or
Error::UnknownCommand if no handler is registered for name.
Sourcepub fn call_or_error_bytes(&self, name: &str, payload: Vec<u8>) -> Vec<u8> ⓘ
pub fn call_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§
Auto Trait Implementations§
impl !Freeze for Router
impl RefUnwindSafe for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl UnsafeUnpin for Router
impl UnwindSafe for Router
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