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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

source

pub fn new() -> Self

Create a new Router.

source

pub fn routers(&self) -> &Vec<Router>

Get current router’s children reference.

source

pub fn routes_mut(&mut self) -> &mut Vec<Router>

Get current router’s children mutable reference.

source

pub fn hoops(&self) -> &Vec<Rc<dyn Handler>>

Get current router’s middlewares reference.

source

pub fn hoops_mut(&mut self) -> &mut Vec<Rc<dyn Handler>>

Get current router’s middlewares mutable reference.

source

pub fn filters(&self) -> &Vec<Box<dyn Filter>>

Get current router’s filters reference.

source

pub fn filters_mut(&mut self) -> &mut Vec<Box<dyn Filter>>

Get current router’s filters mutable reference.

source

pub fn detect( &self, url: &Url, truck: &Truck, path_state: &mut PathState ) -> Option<DetectMatched>

Detect current router is matched for current request.

source

pub fn push(self, router: Router) -> Self

Push a router as child of current router.

source

pub fn append(self, others: &mut Vec<Router>) -> Self

Append all routers in a Vec as children of current router.

source

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.

source

pub fn with_hoop_when<H, F>(hoop: H, filter: F) -> Self
where H: Handler, F: Fn(&Truck) -> bool + 'static,

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.

source

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.

source

pub fn hoop_when<H, F>(self, hoop: H, filter: F) -> Self
where H: Handler, F: Fn(&Truck) -> bool + 'static,

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.

source

pub fn with_path(path: impl Into<String>) -> Self

Create a new router and set path filter.

Panics

Panics if path value is not in correct format.

source

pub fn path(self, path: impl Into<String>) -> Self

Create a new path filter for current router.

Panics

Panics if path value is not in correct format.

source

pub fn with_filter(filter: impl Filter + Sized) -> Self

Create a new router and set filter.

source

pub fn filter(self, filter: impl Filter + Sized) -> Self

Add a filter for current router.

source

pub fn with_filter_fn<T>(func: T) -> Self
where T: Fn(&Url, &Truck, &mut PathState) -> bool + 'static,

Create a new router and set filter_fn.

source

pub fn filter_fn<T>(self, func: T) -> Self
where T: Fn(&Url, &Truck, &mut PathState) -> bool + 'static,

Create a new FnFilter from Fn.

source

pub fn goal<H: Handler>(self, goal: H) -> Self

Sets current router’s goal handler.

source

pub fn then<F>(self, func: F) -> Self
where F: FnOnce(Self) -> Self,

When you want write router chain, this function will be useful, You can write your custom logic in FnOnce.

Trait Implementations§

source§

impl Debug for Router

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Router

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Router

§

impl !Send for Router

§

impl !Sync for Router

§

impl Unpin for Router

§

impl !UnwindSafe for Router

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>,

§

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

§

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

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more