Routes

Struct Routes 

Source
pub struct Routes { /* private fields */ }
Expand description

§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§

Source§

impl Routes

Source

pub async fn new() -> Self

§New

Create a new Route struct

Source

pub async fn add_route(&mut self, route: String, content: Route)

§Add Route

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

Source

pub async fn get_route( &self, request: String, user_addr: SocketAddr, is_secure: bool, ) -> Result<DataType, &str>

§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.

If this function detects a request for static content - which it can only detect if the data is stored in /static/, then it will return early with the static content, and not run any functions.

If an error handler is not set, and a route is not found, a panic will occur.

Auto Trait Implementations§

§

impl Freeze for Routes

§

impl !RefUnwindSafe for Routes

§

impl !Send for Routes

§

impl !Sync for Routes

§

impl Unpin for Routes

§

impl !UnwindSafe for Routes

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.