pub struct WorkerRouter;Expand description
Per-worker router accessor.
This provides zero-cost access to the router without Arc cloning.
Implementations§
Source§impl WorkerRouter
impl WorkerRouter
Sourcepub fn with<F, R>(f: F) -> R
pub fn with<F, R>(f: F) -> R
Execute a closure with the worker’s router.
This is the primary way to access the router without cloning. The closure receives a reference to the router.
§Panics
Panics if called from a thread without an initialized worker router.
Use try_with for a non-panicking version.
§Example
ⓘ
let response = WorkerRouter::with(|router| {
router.route(request).await
});Sourcepub fn try_with<F, R>(f: F) -> Option<R>
pub fn try_with<F, R>(f: F) -> Option<R>
Try to execute a closure with the worker’s router.
Returns None if no worker router is initialized.
Sourcepub fn clone_arc() -> Option<Arc<Router>>
pub fn clone_arc() -> Option<Arc<Router>>
Get a clone of the worker’s router (fallback for async contexts).
Use this when you need to move the router into an async block. This still clones the Arc, but only once per request instead of multiple times in nested closures.
Sourcepub fn clone_arc_or_panic() -> Arc<Router>
pub fn clone_arc_or_panic() -> Arc<Router>
Get a clone of the worker’s router, or panic if not initialized.
Auto Trait Implementations§
impl Freeze for WorkerRouter
impl RefUnwindSafe for WorkerRouter
impl Send for WorkerRouter
impl Sync for WorkerRouter
impl Unpin for WorkerRouter
impl UnwindSafe for WorkerRouter
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
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging