Skip to main content

ApiRoute

Trait ApiRoute 

Source
pub trait ApiRoute<S>
where S: Clone + Send + Sync + 'static,
{ // Required method fn api_route<H, T>( self, route_info: (&'static str, &'static str), handler: H, ) -> Self where H: Handler<T, S>, T: 'static; }
Expand description

Extension trait for registering routes using the macro-generated (&'static str, &'static str) route info tuple.

This is the enforcement contract: the HTTP verb in the route info tuple (set by the #[get], #[post], etc. annotation) is the sole authority on the HTTP method. It is impossible to accidentally register a #[get] handler as a POST endpoint.

§Example

// health_check is annotated #[get("/health")], so __health_check_route is
// ("/health", "GET"). api_route enforces that it is registered as GET.
router.api_route(__health_check_route, health_check)

Required Methods§

Source

fn api_route<H, T>( self, route_info: (&'static str, &'static str), handler: H, ) -> Self
where H: Handler<T, S>, T: 'static,

Register a handler using the (path, method) tuple produced by a route macro annotation. The HTTP verb is taken from the tuple — it cannot be overridden at the call site.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S> ApiRoute<S> for Router<S>
where S: Clone + Send + Sync + 'static,