[][src]Struct reign_router::Router

pub struct Router<'a> { /* fields omitted */ }

Helper to define the routing

Examples

use reign::router::Router;

fn router(r: &mut Router) {
    r.get("foo", foo);

    r.scope("bar", |r| {
        r.post("", bar);
        r.delete("baz", baz);
    });
}

Implementations

impl<'a> Router<'a>[src]

pub fn pipe(&mut self, pipe: Pipe<'a>)[src]

pub fn scope<P, R>(&mut self, path: P, f: R) where
    P: Into<Path<'a>>,
    R: Fn(&mut Router), 
[src]

pub fn scope_through<P, R>(&mut self, path: P, pipes: &[&'a str], f: R) where
    P: Into<Path<'a>>,
    R: Fn(&mut Router), 
[src]

Define a scope that runs a middleware pipe

Examples

use reign::router::{Router, Pipe, middleware::Runtime};

fn router(r: &mut Router) {
    r.pipe(Pipe::new("common").add(Runtime::default()));

    r.scope_through("foo", &["common"], |r| {
        r.get("", foo);
   });
}

pub fn scope_as(&mut self, scope: Scope<'a>)[src]

pub fn get<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn post<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn put<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn patch<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn delete<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn head<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn options<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn trace<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn connect<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

pub fn any<P, H>(&mut self, methods: &[Method], path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

Any of the given methods allowed

Examples

use reign::router::{Router, hyper::Method};

fn router(r: &mut Router) {
    r.any(&[Method::GET], "foo", foo);
}

pub fn all<P, H>(&mut self, path: P, handler: H) where
    P: Into<Path<'a>>,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

All methods allowed

pub fn any_with_constraint<P, C, H>(
    &mut self,
    methods: &[Method],
    path: P,
    constraint: C,
    handler: H
) where
    P: Into<Path<'a>>,
    C: Fn(&Request) -> bool + Send + Sync + 'static,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

Any of the given methods allowed with given constraint

Examples

use reign::router::{Router, hyper::Method};

fn router(r: &mut Router) {
    r.any_with_constraint(&[Method::GET], "foo", |req| {
        req.uri().port().is_some() || req.query("bar").is_some()
   }, foo);
}

pub fn all_with_constraint<P, C, H>(
    &mut self,
    path: P,
    constraint: C,
    handler: H
) where
    P: Into<Path<'a>>,
    C: Fn(&Request) -> bool + Send + Sync + 'static,
    H: Fn(&mut Request) -> HandleFuture + Send + Sync + 'static, 
[src]

All methods allowed with given constraint

Trait Implementations

impl<'a> Default for Router<'a>[src]

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Router<'a>

impl<'a> Send for Router<'a>

impl<'a> Sync for Router<'a>

impl<'a> Unpin for Router<'a>

impl<'a> !UnwindSafe for Router<'a>

Blanket Implementations

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

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

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

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

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

impl<T> Sealed<T> for T where
    T: ?Sized

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.

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,