pub struct Service { /* private fields */ }Expand description
A built application, ready to handle requests.
Implementations§
Source§impl Service
impl Service
pub fn router(&self) -> &Router
pub fn env(&self) -> Env
Sourcepub async fn call(&self, req: Request<Bytes>) -> Response
pub async fn call(&self, req: Request<Bytes>) -> Response
Runs one request through middleware and the router. Panics in handlers are caught and turned into a 500.
Sourcepub async fn serve(self, addr: impl ToSocketAddrs) -> Result<()>
pub async fn serve(self, addr: impl ToSocketAddrs) -> Result<()>
Binds addr and serves until Ctrl-C or SIGTERM. Run with a command
instead, the app binary does that and exits, for production, where
there’s no glacier CLI: app migrate, app rollback 2, app seed, app status (the migrations) and app routes.
Sourcepub async fn migrate_named(&self) -> Result<Vec<String>>
pub async fn migrate_named(&self) -> Result<Vec<String>>
Runs the named databases’ migrations: for tests, whose databases
start empty. glacier db migrate runs them too.
Sourcepub async fn run_task(&self, task: &str) -> Result<()>
pub async fn run_task(&self, task: &str) -> Result<()>
Runs a CLI task: routes, db:migrate (every database),
db:rollback (steps from GLACIER_STEPS, default 1, on
GLACIER_DATABASE or the app’s own) or db:status.
Sourcepub fn openapi(&self) -> Value
pub fn openapi(&self) -> Value
The app’s OpenAPI document, named and versioned from its package
(as cargo run sets CARGO_PKG_NAME and CARGO_PKG_VERSION).
With GLACIER_API_VERSION, for that API version (see
Router::version).
Sourcepub async fn dump_schema(&self) -> Result<Vec<String>>
pub async fn dump_schema(&self) -> Result<Vec<String>>
Writes each database’s schema as SQL: db/schema.sql, and
db/<name>/schema.sql for named databases with migrations.
Returns the paths written.
Sourcepub async fn seed(&self) -> Result<()>
pub async fn seed(&self) -> Result<()>
Loads the seeds in one transaction on the app’s database, with the named databases ambient.
Sourcepub async fn run_app_task(&self, name: &str, args: Vec<String>) -> Result<()>
pub async fn run_app_task(&self, name: &str, args: Vec<String>) -> Result<()>
Runs the app’s task name with args, with the app’s databases
(when it has them), outside any request.
Sourcepub async fn serve_with_shutdown(
self,
listener: TcpListener,
signal: impl Future<Output = ()>,
) -> Result<()>
pub async fn serve_with_shutdown( self, listener: TcpListener, signal: impl Future<Output = ()>, ) -> Result<()>
Serves connections from listener until signal resolves, then
gives in-flight requests a grace period to finish.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Service
impl !UnwindSafe for Service
impl Freeze for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl UnsafeUnpin for Service
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more