Skip to main content

Router

Struct Router 

Source
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,

Source

pub fn new() -> Self

Creates a new router

Source

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

Source

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§

Source§

impl<C, S> Default for Router<C, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.