pub struct App<State = ()> { /* private fields */ }
Expand description
The main application type.
See the module-level documentation for more information.
Implementations§
§impl<S, State> App<State>where
State: Sync + 'static + Clone + Send,
Router<State>: for<'a> Service<IncomingStream<'a>, Error = Infallible, Response = S> + Send + 'static,
<Router<State> as Service<IncomingStream<'a>>>::Future: for<'a> Send,
S: Service<Request<Body>, Response = Response<Body>, Error = Infallible> + Clone + Send + 'static,
<S as Service<Request<Body>>>::Future: Send,
impl<S, State> App<State>where
State: Sync + 'static + Clone + Send,
Router<State>: for<'a> Service<IncomingStream<'a>, Error = Infallible, Response = S> + Send + 'static,
<Router<State> as Service<IncomingStream<'a>>>::Future: for<'a> Send,
S: Service<Request<Body>, Response = Response<Body>, Error = Infallible> + Clone + Send + 'static,
<S as Service<Request<Body>>>::Future: Send,
pub async fn launch(self) -> Result<CatalyzedApp<S, State>, CatalyzerError>
pub async fn launch(self) -> Result<CatalyzedApp<S, State>, CatalyzerError>
Catalyzes the application and launches it.
This should be the last method called on the App
instance.
§impl<State> App<State>
impl<State> App<State>
pub fn route<Return, Meta, Handler>(
self,
handler: Handler
) -> Result<App<State>, CatalyzerError>where
Handler: Handler<Return, State>,
Meta: HandlerMetadata,
Return: 'static,
pub fn route<Return, Meta, Handler>(
self,
handler: Handler
) -> Result<App<State>, CatalyzerError>where
Handler: Handler<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)?;
pub fn bind<Addr>(self, addr: Addr) -> Result<App<State>, CatalyzerError>where
Addr: ToSocketAddrs,
pub fn bind<Addr>(self, addr: Addr) -> Result<App<State>, CatalyzerError>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 8080
pub 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 });
pub fn service<S>(self, service: S) -> App<State>
pub fn service<S>(self, service: S) -> App<State>
Mounts a service on the application.
This requires a service that implements the CatalyzerService
trait.
Trait 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