Skip to main content

App

Trait App 

Source
pub trait App: Sealed + Sized {
    // Required methods
    fn run(self) -> impl Future<Output = Result<(), RustStreamError>> + Send;
    fn run_until<F>(
        self,
        shutdown: F,
    ) -> impl Future<Output = Result<(), RustStreamError>> + Send
       where F: Future<Output = ()> + Send;
    fn info(&self) -> &AppInfo;
    fn servers(&self) -> &BTreeMap<String, ServerSpec>;
    fn handlers(&self) -> &[HandlerMetadata];
}
Expand description

The functional surface of a built RustStream service: run it, and read the metadata the AsyncAPI generator and the generated CLI need.

Implemented only by RustStream (the trait is sealed), so a builder function can hide the composed middleware / state / publish-pipeline type parameters behind impl App instead of naming RustStream<Stack<..>, St, PublishStack<..>> in full:

use ruststream::memory::MemoryBroker;
use ruststream::runtime::{App, AppInfo, RustStream};

// The return type stays `impl App` however many layers the body composes onto the pipeline.
fn app() -> impl App {
    RustStream::new(AppInfo::new("svc", "0.1.0")).register_broker(MemoryBroker::new())
}

The inherent RustStream::run / RustStream::info methods stay, so naming the concrete type keeps working; this trait only adds the type-erased surface the CLI and spec generator consume. The run futures are Send because the service is driven across task boundaries (the CLI’s block_on, tokio::spawn in tests), so the bound belongs in the signature.

Required Methods§

Source

fn run(self) -> impl Future<Output = Result<(), RustStreamError>> + Send

Runs the service until an interrupt (SIGINT / SIGTERM), then shuts down gracefully.

§Errors

Returns RustStreamError if a broker fails to connect, a subscription fails to open, a dispatch task panics, or a broker fails to shut down.

Source

fn run_until<F>( self, shutdown: F, ) -> impl Future<Output = Result<(), RustStreamError>> + Send
where F: Future<Output = ()> + Send,

Runs the service until shutdown resolves, then shuts down gracefully.

§Errors

Returns RustStreamError under the same conditions as run.

Source

fn info(&self) -> &AppInfo

The service metadata (title, version, description): the AsyncAPI info object.

Source

fn servers(&self) -> &BTreeMap<String, ServerSpec>

The registered AsyncAPI servers, keyed by name.

Source

fn handlers(&self) -> &[HandlerMetadata]

Metadata for every registered handler, in registration order: input to the AsyncAPI generator.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<L: Send, St: Send + Sync, PP: Send> App for RustStream<L, St, PP>