[−][src]Struct saphir::router::Builder
Builder type for the router
Implementations
impl<Controllers: 'static + RouterChain + Unpin + Send + Sync> Builder<Controllers>
[src]
pub fn route<H>(self, route: &str, method: Method, handler: H) -> Self where
H: 'static + DynHandler<Body> + Send + Sync,
[src]
H: 'static + DynHandler<Body> + Send + Sync,
Add a simple request handle to a given path
// Simply declare a handler fn async fn simple_handler(req: Request<Body>) -> impl Responder {200} // Then while building your server // ... builder.route("/simple", Method::GET, simple_handler); // ...
pub fn route_with_guards<H, F, Chain>(
self,
route: &str,
method: Method,
handler: H,
guards: F
) -> Self where
H: 'static + DynHandler<Body> + Send + Sync,
F: FnOnce(GuardBuilder<GuardChainEnd>) -> GuardBuilder<Chain>,
Chain: GuardChain + 'static,
[src]
self,
route: &str,
method: Method,
handler: H,
guards: F
) -> Self where
H: 'static + DynHandler<Body> + Send + Sync,
F: FnOnce(GuardBuilder<GuardChainEnd>) -> GuardBuilder<Chain>,
Chain: GuardChain + 'static,
Add a request handler to a given path behind guards
async fn handler(req: Request<Body>) -> impl Responder { 200 } async fn value_guard(req: Request<Body>) -> Result<Request<Body>, u16> { match req.captures().get("value") { Some(v) if v.eq("allowed_value") => Ok(req), Some(_) => Err(403), None => Err(400), } } builder.route_with_guards("/handler/{value}", Method::GET, handler, |g| { g.apply(value_guard) }); // ...
pub fn controller<C: Controller + Send + Unpin + Sync>(
self,
controller: C
) -> Builder<RouterChainLink<C, Controllers>>
[src]
self,
controller: C
) -> Builder<RouterChainLink<C, Controllers>>
Add a simple request handle to a given path
// Implement controller for your struct struct SimpleController; // Then while building your server // ... builder.controller(SimpleController); // ...
Trait Implementations
Auto Trait Implementations
impl<Chain> !RefUnwindSafe for Builder<Chain>
impl<Chain> Send for Builder<Chain>
impl<Chain> Sync for Builder<Chain>
impl<Chain> Unpin for Builder<Chain>
impl<Chain> UnwindSafe for Builder<Chain> where
Chain: UnwindSafe,
Chain: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,