Router

Struct Router 

Source
pub struct Router<S = ()>
where S: Clone + Send + Sync + 'static,
{ /* private fields */ }
Expand description

Main router for the elif.rs framework

Implementations§

Source§

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

Source

pub fn new() -> Router<S>

Create a new router

Source

pub fn with_state(state: S) -> Router<S>

Create a new router with state

Source

pub fn use_middleware<M>(self, middleware: M) -> Router<S>
where M: Middleware + 'static,

Add global middleware to the router

Source

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

Source

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

Source

pub fn route(self, path: &str) -> RouteBuilder<S>

Create a route builder for defining routes with middleware groups

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn controller<C>(self, controller: C) -> Router<S>
where C: ElifController + 'static,

Register a controller with automatic route registration

Source

pub fn with_ioc_container(self, container: Arc<IocContainer>) -> Router<S>

Set the IoC container for controller dependency injection

Source

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

Source

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

Source

pub fn merge(self, other: Router<S>) -> Router<S>

Merge another ElifRouter - the primary method for composing routers

Source

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.

Source

pub fn into_axum_router(self) -> Router<S>

Get the underlying Axum router

Source

pub fn registry(&self) -> Arc<Mutex<RouteRegistry>>

Get route registry for introspection

Source

pub fn url_for( &self, name: &str, params: &HashMap<String, String>, ) -> Option<String>

Generate URL for a named route

Source

pub fn middleware_pipeline(&self) -> &MiddlewarePipelineV2

Get the global middleware pipeline

Source

pub fn middleware_groups(&self) -> &HashMap<String, MiddlewarePipelineV2>

Get available middleware groups

Source

pub fn route_middleware(&self) -> &HashMap<String, Vec<String>>

Get route-specific middleware mappings

Source

pub fn controller_registry(&self) -> Arc<Mutex<ControllerRegistry>>

Get the controller registry for introspection

Source

pub fn ioc_container(&self) -> Option<&Arc<IocContainer>>

Get the IoC container if set

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

fn default() -> Router<S>

Returns the “default value” for a type. Read more

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,