use std::collections::BTreeMap;
use std::future::Future;
use crate::ServerSpec;
use crate::runtime::metadata::HandlerMetadata;
use super::{AppInfo, RunningApp, RustStream, RustStreamError};
mod sealed {
#[cfg(feature = "testing")]
use crate::runtime::TestParts;
pub trait Sealed {
#[cfg(feature = "testing")]
type State: Send + Sync + 'static;
#[cfg(feature = "testing")]
fn into_test_parts(self) -> TestParts<Self::State>;
}
#[cfg(not(feature = "testing"))]
impl<Layers, State, Pipeline, Phase> Sealed for super::RustStream<Layers, State, Pipeline, Phase> {}
#[cfg(feature = "testing")]
#[allow(clippy::use_self)]
impl<Layers, State, Pipeline, Phase> Sealed for super::RustStream<Layers, State, Pipeline, Phase>
where
State: Send + Sync + 'static,
{
type State = State;
fn into_test_parts(self) -> TestParts<State> {
super::RustStream::into_test_parts(self)
}
}
}
pub trait App: sealed::Sealed + Sized {
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 start(self) -> impl Future<Output = Result<RunningApp, RustStreamError>> + Send;
fn info(&self) -> &AppInfo;
fn servers(&self) -> &BTreeMap<String, ServerSpec>;
fn handlers(&self) -> &[HandlerMetadata];
}
#[allow(clippy::use_self)]
impl<Layers: Send, State: Send + Sync + 'static, Pipeline: Send, Phase> App
for RustStream<Layers, State, Pipeline, Phase>
{
fn run(self) -> impl Future<Output = Result<(), RustStreamError>> + Send {
RustStream::run(self)
}
fn run_until<F>(self, shutdown: F) -> impl Future<Output = Result<(), RustStreamError>> + Send
where
F: Future<Output = ()> + Send,
{
RustStream::run_until(self, shutdown)
}
fn start(self) -> impl Future<Output = Result<RunningApp, RustStreamError>> + Send {
RustStream::start(self)
}
fn info(&self) -> &AppInfo {
RustStream::info(self)
}
fn servers(&self) -> &BTreeMap<String, ServerSpec> {
RustStream::servers(self)
}
fn handlers(&self) -> &[HandlerMetadata] {
RustStream::handlers(self)
}
}