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 8080Trait Implementations§
Auto Trait Implementations§
impl<State> Freeze for App<State>
impl<State = ()> !RefUnwindSafe for App<State>
impl<State> Send for App<State>
impl<State> Sync for App<State>
impl<State> Unpin for App<State>
impl<State = ()> !UnwindSafe for App<State>
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
Mutably borrows from an owned value. Read more