pub struct RootHandlerBuilder<S = RouterService, SE = DynErrorPageHandler> { /* private fields */ }Expand description
A helper struct to build the root handler for the project.
This is mainly useful for attaching middlewares to the project.
§Examples
use cot::Project;
use cot::middleware::LiveReloadMiddleware;
use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
struct MyProject;
impl Project for MyProject {
fn middlewares(
&self,
handler: RootHandlerBuilder,
context: &MiddlewareContext,
) -> RootHandler {
handler
.middleware(LiveReloadMiddleware::from_context(context))
.build()
}
}Implementations§
Source§impl<RootService, ErrorHandlerService> RootHandlerBuilder<RootService, ErrorHandlerService>
impl<RootService, ErrorHandlerService> RootHandlerBuilder<RootService, ErrorHandlerService>
Sourcepub fn middleware<M>(
self,
middleware: M,
) -> RootHandlerBuilder<WrappedMiddleware<M, RootService>, WrappedMiddleware<M, ErrorHandlerService>>
pub fn middleware<M>( self, middleware: M, ) -> RootHandlerBuilder<WrappedMiddleware<M, RootService>, WrappedMiddleware<M, ErrorHandlerService>>
Adds middleware to the project.
This method is used to add middleware to the project. The middleware will be applied to all routes in the project.
§Examples
use cot::Project;
use cot::middleware::LiveReloadMiddleware;
use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
struct MyProject;
impl Project for MyProject {
fn middlewares(
&self,
handler: RootHandlerBuilder,
context: &MiddlewareContext,
) -> RootHandler {
handler
.middleware(LiveReloadMiddleware::from_context(context))
.build()
}
}Sourcepub fn main_handler_middleware<M>(
self,
middleware: M,
) -> RootHandlerBuilder<WrappedMiddleware<M, RootService>, ErrorHandlerService>where
M: Layer<RootService>,
pub fn main_handler_middleware<M>(
self,
middleware: M,
) -> RootHandlerBuilder<WrappedMiddleware<M, RootService>, ErrorHandlerService>where
M: Layer<RootService>,
Adds middleware only to the main request handler.
This method is used to add middleware that should only be applied to the main request handler, not to the error handler. This is useful when you have middleware that should only run for successful requests, such as logging middleware that should not interfere with error handling.
§Examples
use cot::Project;
use cot::middleware::LiveReloadMiddleware;
use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
struct MyProject;
impl Project for MyProject {
fn middlewares(
&self,
handler: RootHandlerBuilder,
context: &MiddlewareContext,
) -> RootHandler {
handler
.main_handler_middleware(LiveReloadMiddleware::from_context(context))
.build()
}
}Sourcepub fn error_handler_middleware<M>(
self,
middleware: M,
) -> RootHandlerBuilder<RootService, WrappedMiddleware<M, ErrorHandlerService>>where
M: Layer<ErrorHandlerService>,
pub fn error_handler_middleware<M>(
self,
middleware: M,
) -> RootHandlerBuilder<RootService, WrappedMiddleware<M, ErrorHandlerService>>where
M: Layer<ErrorHandlerService>,
Adds middleware only to the error handler.
This method is used to add middleware that should only be applied to the error handler, not to the main request handler. This is useful when you have middleware that should only run when handling errors, such as error reporting middleware or middleware that modifies error responses.
§Examples
use cot::Project;
use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
use cot::static_files::StaticFilesMiddleware;
struct MyProject;
impl Project for MyProject {
fn middlewares(
&self,
handler: RootHandlerBuilder,
context: &MiddlewareContext,
) -> RootHandler {
handler
.error_handler_middleware(StaticFilesMiddleware::from_context(context))
.build()
}
}Sourcepub fn build(self) -> RootHandler
pub fn build(self) -> RootHandler
Builds the root handler for the project.
§Examples
use cot::Project;
use cot::middleware::LiveReloadMiddleware;
use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
struct MyProject;
impl Project for MyProject {
fn middlewares(
&self,
handler: RootHandlerBuilder,
context: &MiddlewareContext,
) -> RootHandler {
handler
.middleware(LiveReloadMiddleware::from_context(context))
.build()
}
}Trait Implementations§
Source§impl<S: Clone, SE: Clone> Clone for RootHandlerBuilder<S, SE>
impl<S: Clone, SE: Clone> Clone for RootHandlerBuilder<S, SE>
Source§fn clone(&self) -> RootHandlerBuilder<S, SE>
fn clone(&self) -> RootHandlerBuilder<S, SE>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<S, SE> Debug for RootHandlerBuilder<S, SE>
impl<S, SE> Debug for RootHandlerBuilder<S, SE>
impl<S: Eq, SE: Eq> Eq for RootHandlerBuilder<S, SE>
impl<S, SE> StructuralPartialEq for RootHandlerBuilder<S, SE>
Auto Trait Implementations§
impl<S, SE> Freeze for RootHandlerBuilder<S, SE>
impl<S, SE> RefUnwindSafe for RootHandlerBuilder<S, SE>where
S: RefUnwindSafe,
SE: RefUnwindSafe,
impl<S, SE> Send for RootHandlerBuilder<S, SE>
impl<S, SE> Sync for RootHandlerBuilder<S, SE>
impl<S, SE> Unpin for RootHandlerBuilder<S, SE>
impl<S, SE> UnsafeUnpin for RootHandlerBuilder<S, SE>where
S: UnsafeUnpin,
SE: UnsafeUnpin,
impl<S, SE> UnwindSafe for RootHandlerBuilder<S, SE>where
S: UnwindSafe,
SE: UnwindSafe,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 moreSource§impl<T> IntoField<Auto<T>> for T
impl<T> IntoField<Auto<T>> for T
Source§fn into_field(self) -> Auto<T>
fn into_field(self) -> Auto<T>
db only.