pub struct Router<C, S> { /* private fields */ }Expand description
Route implementation for storing components mapped to route handlers
Implementations§
Source§impl<C, S> Router<C, S>where
C: PacketComponents,
S: Send + 'static,
impl<C, S> Router<C, S>where
C: PacketComponents,
S: Send + 'static,
Sourcepub fn route<Format, Req, Res>(
&mut self,
component: C,
route: impl for<'a> Handler<'a, S, Format, Req, Res>,
)where
Req: FromRequestInternal,
Res: IntoResponse,
Format: 'static,
pub fn route<Format, Req, Res>(
&mut self,
component: C,
route: impl for<'a> Handler<'a, S, Format, Req, Res>,
)where
Req: FromRequestInternal,
Res: IntoResponse,
Format: 'static,
Adds a new route to the router where the route is something that implements the handler type with any lifetime. The value is wrapped with a HandlerRoute and stored boxed in the routes map under the component key
component The component key for the route
route The actual route handler function
Sourcepub fn handle<'a>(
&self,
state: &'a mut S,
packet: Packet,
) -> Result<Pin<Box<dyn Future<Output = Packet> + Send + 'a>>, HandleError>
pub fn handle<'a>( &self, state: &'a mut S, packet: Packet, ) -> Result<Pin<Box<dyn Future<Output = Packet> + Send + 'a>>, HandleError>
Handle function takes the provided packet retrieves the component from its header and finds the matching route (Returning an empty response immediately if none match) and providing the state the route along with the packet awaiting the route future
state The provided state
packet The packet to handle
Trait Implementations§
Auto Trait Implementations§
impl<C, S> Freeze for Router<C, S>
impl<C, S> !RefUnwindSafe for Router<C, S>
impl<C, S> Send for Router<C, S>where
C: Send,
impl<C, S> Sync for Router<C, S>where
C: Sync,
impl<C, S> Unpin for Router<C, S>where
C: Unpin,
impl<C, S> UnsafeUnpin for Router<C, S>
impl<C, S> !UnwindSafe for Router<C, S>
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