Struct glory_routing::Router
source · #[non_exhaustive]pub struct Router {
pub routers: Vec<Router>,
pub filters: Vec<Box<dyn Filter>>,
pub hoops: Vec<Rc<dyn Handler>>,
pub goal: Option<Rc<dyn Handler>>,
}Expand description
Router struct is used for router request to different handlers.
This form of definition can make the definition of router clear and simple for complex projects.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.routers: Vec<Router>routers is the children of current router.
filters: Vec<Box<dyn Filter>>filters is the filters of current router.
hoops: Vec<Rc<dyn Handler>>hoops of current router.
goal: Option<Rc<dyn Handler>>goal of current router.
Implementations§
source§impl Router
impl Router
sourcepub fn routes_mut(&mut self) -> &mut Vec<Router>
pub fn routes_mut(&mut self) -> &mut Vec<Router>
Get current router’s children mutable reference.
sourcepub fn hoops_mut(&mut self) -> &mut Vec<Rc<dyn Handler>>
pub fn hoops_mut(&mut self) -> &mut Vec<Rc<dyn Handler>>
Get current router’s middlewares mutable reference.
sourcepub fn filters_mut(&mut self) -> &mut Vec<Box<dyn Filter>>
pub fn filters_mut(&mut self) -> &mut Vec<Box<dyn Filter>>
Get current router’s filters mutable reference.
sourcepub fn detect(
&self,
url: &Url,
truck: &Truck,
path_state: &mut PathState
) -> Option<DetectMatched>
pub fn detect( &self, url: &Url, truck: &Truck, path_state: &mut PathState ) -> Option<DetectMatched>
Detect current router is matched for current request.
sourcepub fn append(self, others: &mut Vec<Router>) -> Self
pub fn append(self, others: &mut Vec<Router>) -> Self
Append all routers in a Vec as children of current router.
sourcepub fn with_hoop<H: Handler>(handler: H) -> Self
pub fn with_hoop<H: Handler>(handler: H) -> Self
Add a handler as middleware, it will run the handler in current router or it’s descendants handle the request.
sourcepub fn with_hoop_when<H, F>(hoop: H, filter: F) -> Self
pub fn with_hoop_when<H, F>(hoop: H, filter: F) -> Self
Add a handler as middleware, it will run the handler in current router or it’s descendants handle the request. This middleware only effective when the filter return true.
sourcepub fn hoop<H: Handler>(self, hoop: H) -> Self
pub fn hoop<H: Handler>(self, hoop: H) -> Self
Add a handler as middleware, it will run the handler in current router or it’s descendants handle the request.
sourcepub fn hoop_when<H, F>(self, hoop: H, filter: F) -> Self
pub fn hoop_when<H, F>(self, hoop: H, filter: F) -> Self
Add a handler as middleware, it will run the handler in current router or it’s descendants handle the request. This middleware only effective when the filter return true.
sourcepub fn with_filter(filter: impl Filter + Sized) -> Self
pub fn with_filter(filter: impl Filter + Sized) -> Self
Create a new router and set filter.
sourcepub fn with_filter_fn<T>(func: T) -> Self
pub fn with_filter_fn<T>(func: T) -> Self
Create a new router and set filter_fn.