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
Compares and returns the maximum of two values. Read more
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 lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Node
Auto Trait Implementations
impl RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl !UnwindSafe for Node
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more