Skip to main content

Resource

Trait Resource 

Source
pub trait Resource:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn health_check(&self) -> Result<(), RuntimeError>;
    fn shutdown(&self) -> Result<(), RuntimeError>;
}
Expand description

A managed external resource that participates in the runtime lifecycle.

Implement this trait on database pools, caches, message brokers, or any long-lived resource that needs health checking and graceful shutdown.

All methods are synchronous. Health checks run via block_in_place on a background thread. Shutdown runs during runtime teardown before Tokio shuts down.

Required Methods§

Source

fn name(&self) -> &str

Human-readable name for health reporting and error messages.

Source

fn health_check(&self) -> Result<(), RuntimeError>

Check whether the resource is healthy. Called on a background interval.

Source

fn shutdown(&self) -> Result<(), RuntimeError>

Graceful shutdown. Called in reverse registration order during teardown.

Implementors§