Struct matchit::Node[][src]

pub struct Node<T> { /* fields omitted */ }
Expand description

A node in a radix tree ordered by priority.

Priority is just the number of values registered in sub nodes (children, grandchildren, and so on..).

Implementations

impl<T> Node<T>[src]

pub fn new() -> Self[src]

Construct a new Node.

pub fn insert(
    &mut self,
    route: impl Into<String>,
    val: T
) -> Result<(), InsertError>
[src]

Register a value in the tree under the given route.

let mut matcher = Node::new();
matcher.insert("/home", "Welcome!")?;
matcher.insert("/users/:id", "A User")?;

pub fn at<'p>(&self, path: &'p str) -> Result<Match<'_, 'p, &T>, MatchError>[src]

Tries to find a value in the router matching the given path. If no value can be found it returns a trailing slash redirect recommendation, see tsr.

let mut matcher = Node::new();
matcher.insert("/home", "Welcome!")?;

let matched = matcher.at("/home").unwrap();
assert_eq!(*matched.value, "Welcome!");

pub fn at_mut<'p>(
    &mut self,
    path: &'p str
) -> Result<Match<'_, 'p, &mut T>, MatchError>
[src]

Tries to find a value in the router matching the given path, and returns a mutable reference to it. If no value can be found it returns a trailing slash redirect recommendation, see tsr.

pub fn path_ignore_case(
    &self,
    path: impl AsRef<str>,
    fix_trailing_slash: bool
) -> Option<String>
[src]

Makes a case-insensitive match of the given path and tries to find a handler. It can optionally also fix trailing slashes. If the match is successful, it returns the case corrected path.


let mut matcher = Node::new();
matcher.insert("/home", "Welcome!")?;

let path = matcher.path_ignore_case("/HoMe/", true).unwrap();
assert_eq!(path, "/home");

Trait Implementations

impl<T> Default for Node<T>[src]

fn default() -> Self[src]

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

Auto Trait Implementations

impl<T> !RefUnwindSafe for Node<T>

impl<T> Send for Node<T> where
    T: Send

impl<T> !Sync for Node<T>

impl<T> Unpin for Node<T> where
    T: Unpin

impl<T> UnwindSafe for Node<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.