Struct micro_http_async::Routes [−][src]
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]
&mut self,
route: String,
content: Pin<Box<dyn Fn(Request) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>>>>
)
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]
&self,
request: String,
user_addr: SocketAddr
) -> Result<String, &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.
Auto Trait Implementations
impl !RefUnwindSafe for Routes
[src]
impl !Send for Routes
[src]
impl !Sync for Routes
[src]
impl Unpin for Routes
[src]
impl !UnwindSafe for Routes
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,