Struct micro_http_async::Routes[][src]

pub struct Routes { /* fields omitted */ }

Routes

This struct defines the routes. It uses a hashmap to do this.

HashMap<Route, Content> where content is the return content (ie, html or json).

Implementations

impl Routes[src]

pub async fn new() -> Self[src]

New

Create a new Route struct

pub async fn add_route(
    &mut self,
    route: String,
    content: Pin<Box<dyn Fn(Request) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>>>>
)
[src]

Add Route

Adds a new route to the routes hashmap. If the route already exists, its value is updated

pub async fn get_route(
    &self,
    request: String,
    user_addr: SocketAddr
) -> Result<String, &str>
[src]

Get Route

This function takes in the response string from the TcpStream and searches the hashmap for the callback function associated with the route. It then checks that the route is valid, and runs it asynchrynously (using the request so that the callback can make use of the request data)

This function only runs the callback - handling POST and GET requests is up to the callback.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.