Struct catalyzer::App

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,

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>
where State: Clone + Send + Sync + 'static,

pub fn new() -> App<State>

Creates a new App instance.

This is the main entry point for creating a new application.

It is recommended to use the App! macro instead of this method.

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,

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>

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>
where S: CatalyzerService + Clone + Send + 'static, <S as Service<Request<Body>>>::Response: IntoRawResponse, <S as Service<Request<Body>>>::Future: Send + 'static,

Mounts a service on the application.

This requires a service that implements the CatalyzerService trait.

pub fn inner<S2>(self, mapper: fn(_: Router<State>) -> Router<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).

Trait Implementations§

§

impl<State> Debug for App<State>
where State: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,