Struct actix_router::Router
source · pub struct Router<T, U = ()> { /* private fields */ }
Expand description
Resource router.
It matches a routing resource to an ordered list of routes. Each is defined by a
single ResourceDef
and contains two types of custom data:
- The route value, of the generic type
T
. - Some context data, of the generic type
U
, which is only provided to the check function inrecognize_fn
. This parameter defaults to()
and can be omitted if not required.
Implementations§
source§impl<T, U> Router<T, U>
impl<T, U> Router<T, U>
sourcepub fn build() -> RouterBuilder<T, U>
pub fn build() -> RouterBuilder<T, U>
Constructs new RouterBuilder
with empty route list.
sourcepub fn recognize<R>(&self, resource: &mut R) -> Option<(&T, ResourceId)>where
R: Resource,
pub fn recognize<R>(&self, resource: &mut R) -> Option<(&T, ResourceId)>where
R: Resource,
Finds the value in the router that matches a given routing resource.
The match result, including the captured dynamic segments, in the resource
.
sourcepub fn recognize_mut<R>(
&mut self,
resource: &mut R,
) -> Option<(&mut T, ResourceId)>where
R: Resource,
pub fn recognize_mut<R>(
&mut self,
resource: &mut R,
) -> Option<(&mut T, ResourceId)>where
R: Resource,
Same as recognize
but returns a mutable reference to the matched value.
sourcepub fn recognize_fn<R, F>(
&self,
resource: &mut R,
check: F,
) -> Option<(&T, ResourceId)>
pub fn recognize_fn<R, F>( &self, resource: &mut R, check: F, ) -> Option<(&T, ResourceId)>
Finds the value in the router that matches a given routing resource and passes an additional predicate check using context data.
Similar to recognize
. However, before accepting the route as matched,
the check
closure is executed, passing the resource and each route’s context data. If the
closure returns true then the match result is stored into resource
and a reference to
the matched value is returned.
sourcepub fn recognize_mut_fn<R, F>(
&mut self,
resource: &mut R,
check: F,
) -> Option<(&mut T, ResourceId)>
pub fn recognize_mut_fn<R, F>( &mut self, resource: &mut R, check: F, ) -> Option<(&mut T, ResourceId)>
Same as recognize_fn
but returns a mutable reference to the matched
value.