pub struct Node { /* private fields */ }
Expand description
A recursive member of Tree
, representative of segment(s) in a request path.
Each node includes 0..n
Route
instances, which can be further evaluated by the Router
based on a match. Every node may also have 0..n
children to provide the recursive tree
representation.
Implementations
sourceimpl Node
impl Node
sourcepub fn new(segment: &str, segment_type: SegmentType) -> Self
pub fn new(segment: &str, segment_type: SegmentType) -> Self
Creates new Node
for the given segment and type.
sourcepub fn add_child(&mut self, node: Node) -> &mut Self
pub fn add_child(&mut self, node: Node) -> &mut Self
Adds a new child Node
instance to this Node
.
sourcepub fn add_route(
&mut self,
route: Box<dyn Route<ResBody = Body> + Send + Sync>
) -> &mut Self
pub fn add_route(
&mut self,
route: Box<dyn Route<ResBody = Body> + Send + Sync>
) -> &mut Self
Adds a Route
to this Node
, to be potentially evaluated by the Router
.
sourcepub fn borrow_child(
&self,
segment: &str,
segment_type: SegmentType
) -> Option<&Node>
pub fn borrow_child(
&self,
segment: &str,
segment_type: SegmentType
) -> Option<&Node>
Borrows a child Node
based on the defined segment bounds.
sourcepub fn borrow_child_mut(
&mut self,
segment: &str,
segment_type: SegmentType
) -> Option<&mut Node>
pub fn borrow_child_mut(
&mut self,
segment: &str,
segment_type: SegmentType
) -> Option<&mut Node>
Borrows a mutable child Node
based on the defined segment bounds.
sourcepub fn has_child(&self, segment: &str, segment_type: SegmentType) -> bool
pub fn has_child(&self, segment: &str, segment_type: SegmentType) -> bool
Determines if a child exists based on the defined segment bounds.
sourcepub fn is_routable(&self) -> bool
pub fn is_routable(&self) -> bool
Determines if this Node
has any valid Route
values attached.
sourcepub fn match_node<'a>(
&'a self,
segments: &'a [PercentDecoded]
) -> Option<(&'a Node, SegmentMapping<'a>, usize)>
pub fn match_node<'a>(
&'a self,
segments: &'a [PercentDecoded]
) -> Option<(&'a Node, SegmentMapping<'a>, usize)>
Traverses this Node
and its children, attempting to a locate a path of Node
instances
which match all segments of the provided Request
path. The final Node
must have at
least a single Route
attached in order to be returned.
Only the first matching path is returned from this method, and the value is wrapped in
an Option
as there may be no matching node.
Children are searched in a most to least specific order of segments, based on the node
SegmentType
value:
- Static
- Constrained
- Dynamic
- Glob
This method is a wrapping of an internal recursive implementation to mask the required types needed for the recursion.
sourcepub fn segment<'a>(&'a self) -> &'a str
pub fn segment<'a>(&'a self) -> &'a str
Retrieves a reference to the contained segment value.
This is required for lifetime related annotations.
sourcepub fn select_route(
&self,
state: &State
) -> Result<&Box<dyn Route<ResBody = Body> + Send + Sync>, RouteNonMatch>
pub fn select_route(
&self,
state: &State
) -> Result<&Box<dyn Route<ResBody = Body> + Send + Sync>, RouteNonMatch>
Determines if a Route
instance associated with this Node
is willing to Handle
the
request.
Where multiple Route
instances could possibly handle the Request
only the first, ordered
per creation, is invoked.
Where no Route
instances will accept the Request
the resulting Error will be the
union of the RouteNonMatch
values returned from each Route
.
In the situation where all these avenues are exhausted an InternalServerError will be provided.
Trait Implementations
sourceimpl Ord for Node
impl Ord for Node
sourcefn cmp(&self, other: &Node) -> Ordering
fn cmp(&self, other: &Node) -> Ordering
Compares two Node
values to determine an appropriate Ordering
.
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialEq<Node> for Node
impl PartialEq<Node> for Node
sourceimpl PartialOrd<Node> for Node
impl PartialOrd<Node> for Node
sourcefn partial_cmp(&self, other: &Node) -> Option<Ordering>
fn partial_cmp(&self, other: &Node) -> Option<Ordering>
Compares two Node
values to determine an appropriate Ordering
.
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more