pub struct App<State = ()> { /* private fields */ }Expand description
The main application type.
See the module-level documentation for more information.
Implementations§
Source§impl<S, State> App<State>where
State: Clone + Send + Sync + 'static,
Router<State>: for<'a> Service<IncomingStream<'a>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <Router<State> as Service<IncomingStream<'a>>>::Future: Send,
S: Service<RawRequest, Response = RawResponse, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
impl<S, State> App<State>where
State: Clone + Send + Sync + 'static,
Router<State>: for<'a> Service<IncomingStream<'a>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <Router<State> as Service<IncomingStream<'a>>>::Future: Send,
S: Service<RawRequest, Response = RawResponse, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
Sourcepub async fn launch(self) -> Result<CatalyzedApp<S, State>>
pub async fn launch(self) -> Result<CatalyzedApp<S, State>>
Catalyzes the application and launches it.
This should be the last method called on the App instance.
Source§impl<State> App<State>
impl<State> App<State>
Sourcepub fn route<Return, Meta, Handler>(self, handler: Handler) -> Result<Self>where
Handler: AxumHandler<Return, State>,
Meta: HandlerMetadata,
Return: 'static,
pub fn route<Return, Meta, Handler>(self, handler: Handler) -> Result<Self>where
Handler: AxumHandler<Return, State>,
Meta: HandlerMetadata,
Return: 'static,
Mounts a route handler on the application.
This requires a handler that implements the AxumHandler trait.
Additionally, you need to provide a metadata type that implements the
HandlerMetadata trait.
§Example
#[get("/")]
fn index() {
"Hello, world!"
}
let app = App::new()
.route::<_, index_metadata, _>(index)?;Sourcepub fn bind<Addr>(self, addr: Addr) -> Result<Self>where
Addr: ToSocketAddrs,
pub fn bind<Addr>(self, addr: Addr) -> Result<Self>where
Addr: ToSocketAddrs,
Binds the application to a specific address.
This is required before launching the application.
§Example
let app = App::new().bind("0.0.0.0:8080")?;// Localhost on port 8080Sourcepub fn set_state<S2>(self, state: State) -> App<S2>
pub fn set_state<S2>(self, state: State) -> App<S2>
Sets the state of the application.
If your application requires a state, you must set it using this method.
§Example
struct AppState {
counter: u32,
}
let app = App::new()
.set_state(AppState { counter: 0 });Sourcepub fn service<S>(self, service: S) -> Selfwhere
S: CatalyzerService + Clone + Send + 'static,
S::Response: IntoRawResponse,
S::Future: Send + 'static,
pub fn service<S>(self, service: S) -> Selfwhere
S: CatalyzerService + Clone + Send + 'static,
S::Response: IntoRawResponse,
S::Future: Send + 'static,
Mounts a service on the application.
This requires a service that implements the CatalyzerService trait.
Sourcepub fn inner<S2>(
self,
mapper: fn(AxumRouter<State>) -> AxumRouter<S2>,
) -> App<S2>
pub fn inner<S2>( self, mapper: fn(AxumRouter<State>) -> AxumRouter<S2>, ) -> App<S2>
Reveals the inner router of the application.
This is used for advanced use-cases where you need to access the inner router of the application (e.g. for mounting a sub-application or service).