pub struct App<M: Module> { /* private fields */ }Implementations§
Source§impl<M: Module> App<M>
impl<M: Module> App<M>
Sourcepub fn new(
name: &'static str,
version: &'static str,
module_builder: ModuleBuilder<M>,
) -> Self
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.
Sourcepub fn with_component_parameters<C: Component<M>>(
self,
params: C::Parameters,
) -> Selfwhere
M: HasComponent<C::Interface>,
pub fn with_component_parameters<C: Component<M>>(
self,
params: C::Parameters,
) -> Selfwhere
M: HasComponent<C::Interface>,
Set the parameters of the specified component. If the parameters are not manually set, the defaults will be used.
Sourcepub fn with_component_override<I: Interface + ?Sized>(
self,
component: Box<I>,
) -> Selfwhere
M: HasComponent<I>,
pub fn with_component_override<I: Interface + ?Sized>(
self,
component: Box<I>,
) -> Selfwhere
M: HasComponent<I>,
Override a component implementation. This method is best used when the overriding component has no injected dependencies.
Sourcepub fn with_component_override_fn<I: Interface + ?Sized>(
self,
component_fn: ComponentFn<M, I>,
) -> Selfwhere
M: HasComponent<I>,
pub fn with_component_override_fn<I: Interface + ?Sized>(
self,
component_fn: ComponentFn<M, I>,
) -> Selfwhere
M: HasComponent<I>,
Override a component implementation. This method is best used when the overriding component has injected dependencies.
Sourcepub const fn with_routable_preset(self, routable_preset: bool) -> Self
pub const fn with_routable_preset(self, routable_preset: bool) -> Self
Set the preset value of routable.
Sourcepub fn with_unroutable_scribe(
self,
unroutable_scribe: Arc<dyn UnroutableScribe>,
) -> Self
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.
Sourcepub fn path_prefix(self, path: impl Into<String>) -> Self
pub fn path_prefix(self, path: impl Into<String>) -> Self
Sourcepub fn router_push(self, router: Router) -> Self
pub fn router_push(self, router: Router) -> Self
Push a router as child of current router.
Sourcepub fn dm_router_hoop<H: Handler>(self, hoop: H) -> Self
pub fn dm_router_hoop<H: Handler>(self, hoop: H) -> Self
Add middleware for the routes of dynamic modules.
Sourcepub fn dm_router_hoop_when<H, F>(self, hoop: H, filter: F) -> Self
pub fn dm_router_hoop_when<H, F>(self, hoop: H, filter: F) -> Self
Add middleware for the routes of dynamic modules. This middleware only effective when the filter return true.
Sourcepub fn router_then<F>(self, func: F) -> Self
pub fn router_then<F>(self, func: F) -> Self
When you want write router chain, this function will be useful, You can write your custom logic in FnOnce.
Sourcepub fn router_scheme(self, scheme: Scheme) -> Self
pub fn router_scheme(self, scheme: Scheme) -> Self
Add a SchemeFilter to current router.
Sourcepub fn router_host(self, host: impl Into<String>) -> Self
pub fn router_host(self, host: impl Into<String>) -> Self
Add a HostFilter to current router.
Sourcepub fn service_catcher(self, catcher: impl Into<Arc<Catcher>>) -> Self
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));
}Sourcepub fn service_hoop<H: Handler>(self, hoop: H) -> Self
pub fn service_hoop<H: Handler>(self, hoop: H) -> Self
Add a handler as middleware, it will run the handler when request received.
Sourcepub fn service_hoop_when<H, F>(self, hoop: H, filter: F) -> Self
pub fn service_hoop_when<H, F>(self, hoop: H, filter: F) -> Self
Add a handler as middleware, it will run the handler when request received.
This middleware only effective when the filter return true.
Sourcepub fn allowed_media_types<T>(self, allowed_media_types: T) -> Self
pub fn allowed_media_types<T>(self, allowed_media_types: T) -> Self
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]);Sourcepub async fn run(self, local_addr: impl ToSocketAddrs + Send)
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>
impl<M> !UnwindSafe for App<M>
Blanket Implementations§
Source§impl<Data> ApiSuccessResponse for Data
impl<Data> ApiSuccessResponse for Data
fn api_response<Meta>(self, meta: Option<Meta>) -> ApiResponse<Self, Meta>
fn api_response_without_meta<Meta>(self) -> ApiResponse<Self, Meta>
fn api_response_with_meta<Meta>(self, meta: Meta) -> ApiResponse<Self, Meta>
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> FutureTraceExt for Twhere
T: FutureExt,
impl<T> FutureTraceExt for Twhere
T: FutureExt,
Source§fn with_current_context_span(self, otel_span: Span) -> WithContext<Self> ⓘ
fn with_current_context_span(self, otel_span: Span) -> WithContext<Self> ⓘ
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request