Skip to main content

Router

Struct Router 

Source
pub struct Router<T, U = ()> { /* private fields */ }
Expand description

Resource router.

Maps paths to values of type T. Each resource can also have an optional value of type U used by the recognize_*checked methods. Resources are matched in registration order, the first matching resource wins.

Implementations§

Source§

impl<T, U> Router<T, U>

Source

pub fn builder() -> RouterBuilder<T, U>

Creates a router builder.

Source

pub fn recognize<R, P>(&self, resource: &mut R) -> Option<(&T, ResourceId)>
where R: Resource<P>, P: ResourcePath,

Finds the first resource that matches the path.

On a match, the values of dynamic segments are stored in resource, and a prefix match skips the matched part of the path.

Source

pub fn recognize_mut<R, P>( &mut self, resource: &mut R, ) -> Option<(&mut T, ResourceId)>
where R: Resource<P>, P: ResourcePath,

Same as recognize(), returns a mutable reference.

Source

pub fn recognize_checked<R, P, F>( &self, resource: &mut R, check: F, ) -> Option<(&T, ResourceId)>
where F: Fn(&R, Option<&U>) -> bool, R: Resource<P>, P: ResourcePath,

Finds the first resource that matches the path and passes check.

check is called for each matching resource with the resource and the resource’s optional value of type U.

Source

pub fn recognize_checked_mut<R, P, F>( &mut self, resource: &mut R, check: F, ) -> Option<(&mut T, ResourceId)>
where F: Fn(&R, Option<&U>) -> bool, R: Resource<P>, P: ResourcePath,

Same as recognize_checked(), returns a mutable reference.

Trait Implementations§

Source§

impl<T, U> Clone for Router<T, U>
where T: Clone, U: Clone,

Source§

fn clone(&self) -> Router<T, U>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, U> Debug for Router<T, U>
where T: Debug, U: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, U> Freeze for Router<T, U>

§

impl<T, U> RefUnwindSafe for Router<T, U>

§

impl<T, U> Send for Router<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for Router<T, U>
where T: Sync, U: Sync,

§

impl<T, U> Unpin for Router<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnsafeUnpin for Router<T, U>

§

impl<T, U> UnwindSafe for Router<T, U>
where T: UnwindSafe, U: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.