pub struct Route {
pub container: SyncHashMap<String, Arc<Box<dyn Any>>>,
pub middleware: SyncVec<Box<dyn MiddleWare>>,
pub handlers: SyncHashMap<String, HandleBox>,
}Fields§
§container: SyncHashMap<String, Arc<Box<dyn Any>>>§middleware: SyncVec<Box<dyn MiddleWare>>§handlers: SyncHashMap<String, HandleBox>Implementations§
source§impl Route
impl Route
pub fn new() -> Self
sourcepub fn handle_fn<H: Handler + 'static>(&self, url: &str, h: H)
pub fn handle_fn<H: Handler + 'static>(&self, url: &str, h: H)
handle a fn for example:
use mco_http::route::Route;
use mco_http::server::{Request, Response};
let mut route = Route::new();
//Common way
route.handle_fn("/", |req: Request, res: Response| {
res.send(b"Hello World!").unwrap();
});
//or you can use method. It can even nest calls to Handle
fn hello(req: Request, res: Response) {
res.send(b"Hello World!").unwrap();
}
route.handle_fn("/",hello);
sourcepub fn add_middleware<M: MiddleWare + 'static>(&self, m: M)
pub fn add_middleware<M: MiddleWare + 'static>(&self, m: M)
if you take Response. handle be done for example:
use mco_http::server::{Request, Response};
use mco_http::route::Route;
let mut route = Route::new();
route.add_middleware(|req: &mut Request, res: &mut Option<Response>|{
//res.take() //take Response, next handle will be not run
});pub fn insert<T: Any>(&self, key: &str, data: T)
pub fn get<T: Any>(&self, key: &str) -> Option<&T>
Trait Implementations§
source§impl Handler for Route
impl Handler for Route
source§fn check_continue(&self, _: (&Method, &RequestUri, &Headers)) -> StatusCode
fn check_continue(&self, _: (&Method, &RequestUri, &Headers)) -> StatusCode
Called when a Request includes a
Expect: 100-continue header. Read moresource§fn on_connection_start(&self)
fn on_connection_start(&self)
This is run after a connection is received, on a per-connection basis (not a
per-request basis, as a connection with keep-alive may handle multiple
requests)
source§fn on_connection_end(&self)
fn on_connection_end(&self)
This is run before a connection is closed, on a per-connection basis (not a
per-request basis, as a connection with keep-alive may handle multiple
requests)
Auto Trait Implementations§
impl !RefUnwindSafe for Route
impl Send for Route
impl Sync for Route
impl Unpin for Route
impl !UnwindSafe for Route
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