pub struct Router<S = ()>{ /* private fields */ }
Expand description
Main router for the elif.rs framework
Implementations§
Source§impl<S> Router<S>
impl<S> Router<S>
Sourcepub fn with_state(state: S) -> Router<S>
pub fn with_state(state: S) -> Router<S>
Create a new router with state
Sourcepub fn use_middleware<M>(self, middleware: M) -> Router<S>where
M: Middleware + 'static,
pub fn use_middleware<M>(self, middleware: M) -> Router<S>where
M: Middleware + 'static,
Add global middleware to the router
Sourcepub fn extend_middleware(
self,
external_middleware: MiddlewarePipelineV2,
) -> Router<S>
pub fn extend_middleware( self, external_middleware: MiddlewarePipelineV2, ) -> Router<S>
Extend router middleware with external middleware pipeline External middleware will be executed before the router’s own middleware
Sourcepub fn middleware_group(
self,
name: &str,
middleware: Vec<Arc<dyn Middleware>>,
) -> Router<S>
pub fn middleware_group( self, name: &str, middleware: Vec<Arc<dyn Middleware>>, ) -> Router<S>
Create a named middleware group for use with route-specific middleware
Sourcepub fn route(self, path: &str) -> RouteBuilder<S>
pub fn route(self, path: &str) -> RouteBuilder<S>
Create a route builder for defining routes with middleware groups
Sourcepub fn get<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
pub fn get<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
Add a GET route with elif handler
Sourcepub fn post<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
pub fn post<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
Add a POST route with elif handler
Sourcepub fn put<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
pub fn put<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
Add a PUT route with elif handler
Sourcepub fn delete<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
pub fn delete<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
Add a DELETE route with elif handler
Sourcepub fn patch<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
pub fn patch<F, Fut, R>(self, path: &str, handler: F) -> Router<S>where
F: Fn(ElifRequest) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<R, HttpError>> + Send + 'static,
R: IntoElifResponse + Send + 'static,
Add a PATCH route with elif handler
Sourcepub fn controller<C>(self, controller: C) -> Router<S>where
C: ElifController + 'static,
pub fn controller<C>(self, controller: C) -> Router<S>where
C: ElifController + 'static,
Register a controller with automatic route registration
Sourcepub fn with_ioc_container(self, container: Arc<IocContainer>) -> Router<S>
pub fn with_ioc_container(self, container: Arc<IocContainer>) -> Router<S>
Set the IoC container for controller dependency injection
Sourcepub fn controller_from_container<C>(self) -> Router<S>where
C: ElifController + IocControllable + 'static,
pub fn controller_from_container<C>(self) -> Router<S>where
C: ElifController + IocControllable + 'static,
Register a controller type that will be resolved from the IoC container The controller type must implement both ElifController and IocControllable
Sourcepub fn scoped_controller_from_container<C>(self) -> Router<S>where
C: ElifController + IocControllable + 'static,
pub fn scoped_controller_from_container<C>(self) -> Router<S>where
C: ElifController + IocControllable + 'static,
Register a controller type with request-scoped dependency injection This creates controllers per request with scoped dependencies
Sourcepub fn merge(self, other: Router<S>) -> Router<S>
pub fn merge(self, other: Router<S>) -> Router<S>
Merge another ElifRouter - the primary method for composing routers
Sourcepub fn nest(self, path: &str, router: Router<S>) -> Router<S>
pub fn nest(self, path: &str, router: Router<S>) -> Router<S>
Nest routes under a path prefix
The nested router’s global middleware will be applied only to the nested routes, not to the parent router’s routes. This is achieved by converting the nested router’s middleware pipeline into an Axum Layer before nesting.
Sourcepub fn into_axum_router(self) -> Router<S>
pub fn into_axum_router(self) -> Router<S>
Get the underlying Axum router
Sourcepub fn registry(&self) -> Arc<Mutex<RouteRegistry>>
pub fn registry(&self) -> Arc<Mutex<RouteRegistry>>
Get route registry for introspection
Sourcepub fn url_for(
&self,
name: &str,
params: &HashMap<String, String>,
) -> Option<String>
pub fn url_for( &self, name: &str, params: &HashMap<String, String>, ) -> Option<String>
Generate URL for a named route
Sourcepub fn middleware_pipeline(&self) -> &MiddlewarePipelineV2
pub fn middleware_pipeline(&self) -> &MiddlewarePipelineV2
Get the global middleware pipeline
Sourcepub fn middleware_groups(&self) -> &HashMap<String, MiddlewarePipelineV2>
pub fn middleware_groups(&self) -> &HashMap<String, MiddlewarePipelineV2>
Get available middleware groups
Sourcepub fn route_middleware(&self) -> &HashMap<String, Vec<String>>
pub fn route_middleware(&self) -> &HashMap<String, Vec<String>>
Get route-specific middleware mappings
Sourcepub fn controller_registry(&self) -> Arc<Mutex<ControllerRegistry>>
pub fn controller_registry(&self) -> Arc<Mutex<ControllerRegistry>>
Get the controller registry for introspection
Sourcepub fn ioc_container(&self) -> Option<&Arc<IocContainer>>
pub fn ioc_container(&self) -> Option<&Arc<IocContainer>>
Get the IoC container if set
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for Router<S>
impl<S = ()> !RefUnwindSafe for Router<S>
impl<S> Send for Router<S>
impl<S> Sync for Router<S>
impl<S> Unpin for Router<S>
impl<S = ()> !UnwindSafe for Router<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more