Skip to main content

RootHandlerBuilder

Struct RootHandlerBuilder 

Source
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>
where RootService: Service<Request, Response = Response, Error = Error> + Send + Sync + Clone + 'static, RootService::Future: Send, ErrorHandlerService: Service<Request, Response = Response, Error = Error> + Send + Sync + Clone + 'static, ErrorHandlerService::Future: Send,

Source

pub fn middleware<M>( self, middleware: M, ) -> RootHandlerBuilder<WrappedMiddleware<M, RootService>, WrappedMiddleware<M, ErrorHandlerService>>
where M: Layer<RootService> + Layer<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()
    }
}
Source

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()
    }
}
Source

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()
    }
}
Source

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>

Source§

fn clone(&self) -> RootHandlerBuilder<S, SE>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S, SE> Debug for RootHandlerBuilder<S, SE>
where S: Debug, SE: Debug,

Source§

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

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

impl<S: Hash, SE: Hash> Hash for RootHandlerBuilder<S, SE>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<S: PartialEq, SE: PartialEq> PartialEq for RootHandlerBuilder<S, SE>

Source§

fn eq(&self, other: &RootHandlerBuilder<S, SE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: Eq, SE: Eq> Eq for RootHandlerBuilder<S, SE>

Source§

impl<S, SE> StructuralPartialEq for RootHandlerBuilder<S, SE>

Auto Trait Implementations§

§

impl<S, SE> Freeze for RootHandlerBuilder<S, SE>
where S: Freeze, SE: Freeze,

§

impl<S, SE> RefUnwindSafe for RootHandlerBuilder<S, SE>

§

impl<S, SE> Send for RootHandlerBuilder<S, SE>
where S: Send, SE: Send,

§

impl<S, SE> Sync for RootHandlerBuilder<S, SE>
where S: Sync, SE: Sync,

§

impl<S, SE> Unpin for RootHandlerBuilder<S, SE>
where S: Unpin, SE: Unpin,

§

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

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Container<T> for T
where T: Clone,

Source§

type Iter = Once<T>

An iterator over the items within this container, by value.
Source§

fn get_iter(&self) -> <T as Container<T>>::Iter

Iterate over the elements of the container (using internal iteration because GATs are unstable).
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: Rng + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoApi for T

Source§

fn into_api<A>(self) -> UseApi<T, A>

into UseApi
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> IntoField<Auto<T>> for T

Source§

fn into_field(self) -> Auto<T>

Available on crate feature db only.
Converts the type to the field type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> OrderedContainer<T> for T
where T: Clone,