use std::sync::Arc;
use tower_layer::Layer;
use crate::{config::EngineIoConfig, handler::EngineIoHandler, service::EngineIoService};
#[derive(Debug, Clone)]
pub struct EngineIoLayer<H: EngineIoHandler> {
config: EngineIoConfig,
handler: Arc<H>,
}
impl<H: EngineIoHandler> EngineIoLayer<H> {
pub fn new(handler: Arc<H>) -> Self {
Self {
config: EngineIoConfig::default(),
handler,
}
}
pub fn from_config(handler: Arc<H>, config: EngineIoConfig) -> Self {
Self { config, handler }
}
}
impl<S: Clone, H: EngineIoHandler + Clone> Layer<S> for EngineIoLayer<H> {
type Service = EngineIoService<H, S>;
fn layer(&self, inner: S) -> Self::Service {
EngineIoService::with_config_inner(inner, self.handler.clone(), self.config.clone())
}
}