use super::endpoint::HttpEndpoint;
use super::error::WebError;
use super::types::ServerConfig;
use async_trait::async_trait;
#[async_trait]
pub trait WebServer: Send + Sync {
fn register_endpoint(&mut self, endpoint: Box<dyn HttpEndpoint>) -> Result<(), WebError>;
async fn start(self, config: ServerConfig) -> Result<(), WebError>;
fn shutdown_handle(&self) -> Option<Box<dyn ServerShutdownHandle>>;
}
#[async_trait]
pub trait ServerShutdownHandle: Send + Sync {
async fn shutdown(&self) -> Result<(), WebError>;
fn is_running(&self) -> bool;
}
pub trait WebServerBuilder: Sized {
type Server: WebServer;
fn new() -> Self;
fn endpoint(self, endpoint: Box<dyn HttpEndpoint>) -> Self;
fn endpoints(self, endpoints: Vec<Box<dyn HttpEndpoint>>) -> Self;
fn build(self) -> Result<Self::Server, WebError>;
}