pub struct App<M = NoMigrations> { /* private fields */ }Expand description
Application builder: configuration, database, tracing, migrations, and HTTP.
Implementations§
Source§impl<M: MigratorTrait> App<M>
impl<M: MigratorTrait> App<M>
Sourcepub fn service<T: Send + Sync + 'static>(self, service: T) -> Self
pub fn service<T: Send + Sync + 'static>(self, service: T) -> Self
Register or replace a typed dependency for HTTP, workers and tests. Register the same factory in each process; test factories may override a type.
Sourcepub fn storage(self, storage: Storage) -> Self
pub fn storage(self, storage: Storage) -> Self
Register private storage, including isolated memory storage for tests.
Sourcepub fn email_verification(self, delivery: impl VerificationDelivery) -> Self
pub fn email_verification(self, delivery: impl VerificationDelivery) -> Self
Enable authenticated, single-use email verification. Register EmailVerificationMigration after identity and supply private delivery.
Sourcepub fn seeds(
self,
seed: impl for<'a> Fn(SeedContext<'a>) -> SeedFuture<'a> + Send + Sync + 'static,
) -> Self
pub fn seeds( self, seed: impl for<'a> Fn(SeedContext<'a>) -> SeedFuture<'a> + Send + Sync + 'static, ) -> Self
Register explicit development/test seeds, executed only by db:seed or the test harness. The callback shares one database transaction; serving never runs it.
Sourcepub fn on<E: Event>(
self,
listener: impl for<'a> Fn(&'a E, EventContext<'a>) -> EventFuture<'a> + Send + Sync + 'static,
) -> Self
pub fn on<E: Event>( self, listener: impl for<'a> Fn(&'a E, EventContext<'a>) -> EventFuture<'a> + Send + Sync + 'static, ) -> Self
Append a typed transaction listener. Return Box::pin(async move { ... }).
Handlers run in registration order before commit; failure rolls back built-in
auth transitions. Queue external side effects with ctx.jobs().dispatch(job).
Capture additional services explicitly; never send email inside a transaction.
Sourcepub fn mail(self) -> Self
pub fn mail(self) -> Self
Enable configured outbound mail and the shared MailContext extractor. With Jobs, the built-in versioned mail delivery handler is registered automatically.
Sourcepub fn with_mail(self, mailer: Mailer) -> Self
pub fn with_mail(self, mailer: Mailer) -> Self
Use an explicit shared transport, including real-rendering capture in tests.
Sourcepub fn auth(self, delivery: impl ResetDelivery) -> Self
pub fn auth(self, delivery: impl ResetDelivery) -> Self
Install conventional /api/auth routes and synchronizer CSRF protection.
The application owns password-reset delivery. Migrate identity tables first.
Sourcepub fn jobs(self, jobs: Jobs) -> Self
pub fn jobs(self, jobs: Jobs) -> Self
Register durable job handlers. HTTP only dispatches; workers run separately.
Sourcepub fn schedules(self, schedules: Schedules) -> Self
pub fn schedules(self, schedules: Schedules) -> Self
Register durable UTC schedules; the separate scheduler process publishes jobs.
Sourcepub fn openapi_with(
self,
customize: impl Fn(&mut ApiDocument) + Send + Sync + 'static,
) -> Self
pub fn openapi_with( self, customize: impl Fn(&mut ApiDocument) + Send + Sync + 'static, ) -> Self
Customize standard OpenAPI metadata, servers or security schemes. The same function runs during offline export and endpoint generation.
Sourcepub fn openapi(&self) -> Result<ApiDocument>
pub fn openapi(&self) -> Result<ApiDocument>
Generate this application’s explicit contract without opening a database connection.
Sourcepub fn openapi_strict(&self) -> Result<ApiDocument>
pub fn openapi_strict(&self) -> Result<ApiDocument>
Export while rejecting undocumented public API routes, independent of config defaults.
Sourcepub fn observe_requests(self, observer: impl RequestObserver) -> Self
pub fn observe_requests(self, observer: impl RequestObserver) -> Self
Install an application-owned, nonblocking response observer for telemetry.
Sourcepub fn request_timeout_for(
self,
route: impl Into<String>,
timeout: Option<Duration>,
) -> Self
pub fn request_timeout_for( self, route: impl Into<String>, timeout: Option<Duration>, ) -> Self
Override the response-header deadline for a full matched route template,
such as /api/events or /api/posts/{id}. None intentionally disables
it. Response body streaming is never subject to this header deadline.
Sourcepub fn api_routes(self, routes: Routes) -> Self
pub fn api_routes(self, routes: Routes) -> Self
Mount API routes under /api, preserving JSON errors within that namespace.
Declare paths such as /posts without repeating the prefix.
Sourcepub fn frontend(self, directory: impl Into<PathBuf>) -> Self
pub fn frontend(self, directory: impl Into<PathBuf>) -> Self
Serve built frontend assets and use index.html for non-API browser routes. The path is relative to the application’s working directory. Production startup requires a readable index.html; development may use Vite instead.
Sourcepub fn config(self, config: AppConfig) -> Self
pub fn config(self, config: AppConfig) -> Self
Use explicit typed configuration, useful for tests and embedded apps.
Sourcepub fn migrations<N: MigratorTrait>(self, _migrator: N) -> App<N>
pub fn migrations<N: MigratorTrait>(self, _migrator: N) -> App<N>
Register a native SeaORM migrator for the application’s CLI commands. Serving never applies migrations implicitly.
Sourcepub fn into_router(self, context: AppContext) -> Router
pub fn into_router(self, context: AppContext) -> Router
Build a service using an existing context, without binding a TCP port. The returned Axum router can be tested or served with native tooling.
Sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Serve by default, or execute the command forwarded by capy.
Supported arguments: serve, check, routes, migrate, migrate:rollback,
and migrate:status. With jobs enabled, queue:work accepts --queue and
--concurrency; queue:failed, queue:retry UUID, queue:forget UUID and
queue:check share the same binary. Migrations are explicit; rollback reverts one.
Sourcepub async fn run_command(self, command: &str) -> Result<()>
pub async fn run_command(self, command: &str) -> Result<()>
Run a specific application command without reading process arguments.
Trait Implementations§
Source§impl<M: MigratorTrait + Send> TestApplication for App<M>
Available on crate feature testing only.
impl<M: MigratorTrait + Send> TestApplication for App<M>
testing only.Source§fn test_config(&self) -> Result<AppConfig>
fn test_config(&self) -> Result<AppConfig>
Source§async fn boot_test(self, context: AppContext, migrate: bool) -> Result<TestApp>
async fn boot_test(self, context: AppContext, migrate: bool) -> Result<TestApp>
Source§fn capture_test_mail(self, config: &AppConfig) -> Result<(Self, TestMailer)>
fn capture_test_mail(self, config: &AppConfig) -> Result<(Self, TestMailer)>
Auto Trait Implementations§
impl<M = NoMigrations> !RefUnwindSafe for App<M>
impl<M = NoMigrations> !UnwindSafe for App<M>
impl<M> Freeze for App<M>where
PhantomData<M>: Freeze,
impl<M> Send for App<M>where
PhantomData<M>: Send,
impl<M> Sync for App<M>where
PhantomData<M>: Sync,
impl<M> Unpin for App<M>where
PhantomData<M>: Unpin,
impl<M> UnsafeUnpin for App<M>where
PhantomData<M>: UnsafeUnpin,
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> 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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);