App

Struct App 

Source
pub struct App<M: Module> { /* private fields */ }

Implementations§

Source§

impl<M: Module> App<M>

Source

pub fn new( name: &'static str, version: &'static str, module_builder: ModuleBuilder<M>, ) -> Self

It is recommended to use the new_app![ModuleType,...] macro to create an App. This method is mainly provided for use by this macro.

Source

pub fn with_component_parameters<C: Component<M>>( self, params: C::Parameters, ) -> Self
where M: HasComponent<C::Interface>,

Set the parameters of the specified component. If the parameters are not manually set, the defaults will be used.

Source

pub fn with_component_override<I: Interface + ?Sized>( self, component: Box<I>, ) -> Self
where M: HasComponent<I>,

Override a component implementation. This method is best used when the overriding component has no injected dependencies.

Source

pub fn with_component_override_fn<I: Interface + ?Sized>( self, component_fn: ComponentFn<M, I>, ) -> Self
where M: HasComponent<I>,

Override a component implementation. This method is best used when the overriding component has injected dependencies.

Source

pub const fn with_routable_preset(self, routable_preset: bool) -> Self

Set the preset value of routable.

Source

pub fn with_unroutable_scribe( self, unroutable_scribe: Arc<dyn UnroutableScribe>, ) -> Self

Set up a scribe that provides a response when the module is not allowed to be accessed.

Source

pub fn path_prefix(self, path: impl Into<String>) -> Self

Set the global route path prefix.

§Panics

Panics if path value is not in correct format.

Source

pub fn router_push(self, router: Router) -> Self

Push a router as child of current router.

Source

pub fn dm_router_hoop<H: Handler>(self, hoop: H) -> Self

Add middleware for the routes of dynamic modules.

Source

pub fn dm_router_hoop_when<H, F>(self, hoop: H, filter: F) -> Self
where H: Handler, F: Fn(&Request, &Depot) -> bool + Send + Sync + 'static,

Add middleware for the routes of dynamic modules. This middleware only effective when the filter return true.

Source

pub fn router_then<F>(self, func: F) -> Self
where F: FnOnce(Router) -> Router,

When you want write router chain, this function will be useful, You can write your custom logic in FnOnce.

Source

pub fn router_scheme(self, scheme: Scheme) -> Self

Add a SchemeFilter to current router.

Source

pub fn router_host(self, host: impl Into<String>) -> Self

Add a HostFilter to current router.

Source

pub fn service_catcher(self, catcher: impl Into<Arc<Catcher>>) -> Self

When the response code is 400-600 and the body is empty, capture and set the error page content. If catchers is not set, the default error page will be used.

§Example
use dipper::{catcher::Catcher, prelude::*};

#[handler]
async fn handle404(
    &self,
    _req: &Request,
    _depot: &Depot,
    res: &mut Response,
    ctrl: &mut FlowCtrl,
) {
    if let Some(StatusCode::NOT_FOUND) = res.status_code {
        res.render("Custom 404 Error Page");
        ctrl.skip_rest();
    }
}

#[tokio::main]
async fn main() {
    Service::new(Router::new()).catcher(Catcher::default().hoop(handle404));
}
Source

pub fn service_hoop<H: Handler>(self, hoop: H) -> Self

Add a handler as middleware, it will run the handler when request received.

Source

pub fn service_hoop_when<H, F>(self, hoop: H, filter: F) -> Self
where H: Handler, F: Fn(&Request, &Depot) -> bool + Send + Sync + 'static,

Add a handler as middleware, it will run the handler when request received.

This middleware only effective when the filter return true.

Source

pub fn allowed_media_types<T>(self, allowed_media_types: T) -> Self
where T: Into<Arc<Vec<Mime>>>,

Sets allowed media types list and returns Self for write code chained.

§Example

let service = Service::new(Router::new()).allowed_media_types(vec![mime::TEXT_PLAIN]);
Source

pub async fn run(self, local_addr: impl ToSocketAddrs + Send)

Run server. local_addr can be "0.0.0.0:8888".

Auto Trait Implementations§

§

impl<M> !Freeze for App<M>

§

impl<M> !RefUnwindSafe for App<M>

§

impl<M> !Send for App<M>

§

impl<M> !Sync for App<M>

§

impl<M> Unpin for App<M>
where <M as Module>::Submodules: Unpin, M: Unpin,

§

impl<M> !UnwindSafe for App<M>

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<Data> ApiSuccessResponse for Data

Source§

fn api_response<Meta>(self, meta: Option<Meta>) -> ApiResponse<Self, Meta>

Source§

fn api_response_without_meta<Meta>(self) -> ApiResponse<Self, Meta>

Source§

fn api_response_with_meta<Meta>(self, meta: Meta) -> ApiResponse<Self, Meta>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> FutureTraceExt for T
where T: FutureExt,

Source§

fn with_current_context_span(self, otel_span: Span) -> WithContext<Self>

Pass the span of opentelemetry to the current context of tracing.
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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> Any for T
where T: Any,

Source§

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