mod include;
mod run;
mod scope;
mod service;
pub use scope::BrokerScope;
pub use service::RustStream;
use std::sync::Arc;
use thiserror::Error;
use tokio::task::JoinHandle;
use tokio_util::sync::CancellationToken;
use crate::runtime::context::State;
use crate::runtime::failure::ErrorShutdown;
use crate::runtime::lifecycle::{BoxError, BoxFuture};
type Starter = Box<
dyn FnOnce(
Arc<State>,
ErrorShutdown,
CancellationToken,
) -> BoxFuture<'static, Result<JoinHandle<()>, BoxError>>
+ Send,
>;
type StartupHook = Box<dyn FnOnce(State) -> BoxFuture<'static, Result<State, BoxError>> + Send>;
type LifecycleHook = Box<dyn FnOnce(Arc<State>) -> BoxFuture<'static, Result<(), BoxError>> + Send>;
#[derive(Clone, Copy)]
enum LifecyclePhase {
AfterStartup,
OnShutdown,
AfterShutdown,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct AppInfo {
pub title: String,
pub version: String,
pub description: Option<String>,
}
impl AppInfo {
#[must_use]
pub fn new(title: impl Into<String>, version: impl Into<String>) -> Self {
Self {
title: title.into(),
version: version.into(),
description: None,
}
}
#[must_use]
pub fn with_description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum RustStreamError {
#[error("broker connect failed: {0}")]
Connect(#[source] BoxError),
#[error("startup hook failed: {0}")]
Startup(#[source] BoxError),
#[error("subscription failed: {0}")]
Subscribe(#[source] BoxError),
#[error("broker shutdown failed: {0}")]
Shutdown(#[source] BoxError),
#[error("dispatch task failed: {0}")]
Join(#[source] tokio::task::JoinError),
#[error("dispatch failed: {0}")]
Dispatch(String),
}