Struct gotham::router::tree::node::Node

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

source§

impl Node

source

pub fn new(segment: &str, segment_type: SegmentType) -> Self

Creates new Node for the given segment and type.

source

pub fn add_child(&mut self, node: Node) -> &mut Self

Adds a new child Node instance to this Node.

source

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.

source

pub fn borrow_child( &self, segment: &str, segment_type: SegmentType ) -> Option<&Node>

Borrows a child Node based on the defined segment bounds.

source

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.

source

pub fn has_child(&self, segment: &str, segment_type: SegmentType) -> bool

Determines if a child exists based on the defined segment bounds.

source

pub fn is_routable(&self) -> bool

Determines if this Node has any valid Route values attached.

source

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:

  1. Static
  2. Constrained
  3. Dynamic
  4. Glob

This method is a wrapping of an internal recursive implementation to mask the required types needed for the recursion.

source

pub fn segment<'a>(&'a self) -> &'a str

Retrieves a reference to the contained segment value.

This is required for lifetime related annotations.

source

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§

source§

impl Ord for Node

source§

fn cmp(&self, other: &Node) -> Ordering

Compares two Node values to determine an appropriate Ordering.

1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Node> for Node

source§

fn eq(&self, other: &Node) -> bool

Compares two Node values for equality based on the segments they represent.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Node> for Node

source§

fn partial_cmp(&self, other: &Node) -> Option<Ordering>

Compares two Node values to determine an appropriate Ordering.

1.0.0 · source§

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

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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