pub struct Router<TCtx> { /* private fields */ }Expand description
Collection of type-erased procedures, keyed by name.
All procedures share the same TCtx (base context type).
Implementations§
Source§impl<TCtx> Router<TCtx>
impl<TCtx> Router<TCtx>
pub fn new() -> Self
Sourcepub fn procedure(
self,
key: impl Into<String>,
proc: impl Into<ErasedProcedure<TCtx>>,
) -> Self
pub fn procedure( self, key: impl Into<String>, proc: impl Into<ErasedProcedure<TCtx>>, ) -> Self
Add a procedure. Accepts Procedure (auto-erased) or ErasedProcedure.
Panics if the key already exists.
Sourcepub fn nest(self, prefix: &str, router: Router<TCtx>) -> Self
pub fn nest(self, prefix: &str, router: Router<TCtx>) -> Self
Nest a sub-router under a prefix. Keys become prefix.key.
Panics if any nested key collides with an existing key.
Sourcepub fn get(&self, key: &str) -> Option<&ErasedProcedure<TCtx>>
pub fn get(&self, key: &str) -> Option<&ErasedProcedure<TCtx>>
Look up a procedure by key.
Sourcepub fn procedures(&self) -> &HashMap<String, ErasedProcedure<TCtx>>
pub fn procedures(&self) -> &HashMap<String, ErasedProcedure<TCtx>>
Get all procedures.
Trait Implementations§
Auto Trait Implementations§
impl<TCtx> Freeze for Router<TCtx>
impl<TCtx> !RefUnwindSafe for Router<TCtx>
impl<TCtx> Send for Router<TCtx>
impl<TCtx> Sync for Router<TCtx>
impl<TCtx> Unpin for Router<TCtx>
impl<TCtx> UnsafeUnpin for Router<TCtx>
impl<TCtx> !UnwindSafe for Router<TCtx>
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