Skip to main content

App

Struct App 

Source
pub struct App { /* private fields */ }
Expand description

An assembled, immutable, cheaply-cloneable application.

Produced by AppBuilder::build. Internally reference-counted, so cloning is cheap and clones share the same router, middleware, state, and config. Serve it with start (or start_with_shutdown), drive a single request in-process with process, or hand it to a TestClient for testing.

use churust_core::{Churust, Call, TestClient};
let app = Churust::server()
    .routing(|r| { r.get("/", |_c: Call| async { "ok" }); })
    .build();
let clone = app.clone(); // cheap; shares the same inner app
let res = TestClient::new(clone).get("/").send().await;
assert_eq!(res.status().as_u16(), 200);

Implementations§

Source§

impl App

Source

pub fn config(&self) -> &ServerConfig

The resolved ServerConfig this app was built with.

Source

pub async fn process( &self, method: Method, uri: Uri, headers: HeaderMap, body: Bytes, ) -> Response

The single request entry point: run one request through the full pipeline (middleware then routed handler) and return the Response.

Both the hyper engine and the TestClient call this. It is panic-isolated — a panicking handler is caught and turned into 500 Internal Server Error rather than crashing the task.

use churust_core::{Churust, Call};
use http::{HeaderMap, Method};
use bytes::Bytes;
let app = Churust::server()
    .routing(|r| { r.get("/", |_c: Call| async { "ok" }); })
    .build();
let res = app.process(Method::GET, "/".parse().unwrap(), HeaderMap::new(), Bytes::new()).await;
assert_eq!(res.status.as_u16(), 200);

THE single request entry point used by the engine and TestClient. Panic-isolated: a panicking handler yields 500.

Source

pub async fn process_with_extensions( &self, method: Method, uri: Uri, headers: HeaderMap, body: Bytes, extensions: Extensions, ) -> Response

Like App::process, but seeds the Call with pre-built extensions (e.g. a captured WebSocket upgrade handle). Advanced/engine use.

Source

pub async fn start(self) -> Result<()>

Bind the configured address and serve until Ctrl-C (SIGINT), then drain in-flight connections gracefully. Does not return until shutdown.

§Errors

Returns an std::io::Error if the configured host:port is invalid or the socket cannot be bound (e.g. the port is in use).

use churust_core::{Churust, Call};
let app = Churust::server()
    .routing(|r| { r.get("/", |_c: Call| async { "hi" }); })
    .build();
app.start().await
Source

pub async fn start_with_shutdown<F>(self, shutdown: F) -> Result<()>
where F: Future<Output = ()> + Send + 'static,

Bind and serve until the provided shutdown future resolves, then drain gracefully. Use this to wire a custom shutdown signal (e.g. in tests, or to combine SIGTERM with SIGINT).

§Errors

Returns an std::io::Error if the configured host:port is invalid or the socket cannot be bound.

use churust_core::{Churust, Call};
let app = Churust::server()
    .routing(|r| { r.get("/", |_c: Call| async { "hi" }); })
    .build();
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
// ... later: tx.send(()) to trigger shutdown ...
app.start_with_shutdown(async { let _ = rx.await; }).await

Trait Implementations§

Source§

impl Clone for App

Source§

fn clone(&self) -> App

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for App

§

impl !UnwindSafe for App

§

impl Freeze for App

§

impl Send for App

§

impl Sync for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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