diff --git a/src/domain/manager.rs b/src/domain/manager.rs index b3c8deb..9d22e37 100644 --- a/src/domain/manager.rs +++ b/src/domain/manager.rs @@ -1,7 +1,8 @@ use crate::domain::{self, checker, config}; use crate::origin; + use std::error::Error; -use std::future::Future; +use std::future; use std::{pin, sync}; #[derive(thiserror::Error, Debug)] @@ -113,19 +114,30 @@ impl From for SyncWithConfigError { } } -//#[mockall::automock] +//#[mockall::automock( +// type Origin=origin::MockOrigin; +// type SyncWithConfigFuture=future::Ready>; +//)] pub trait Manager { + type Origin<'mgr>: origin::Origin + 'mgr + where + Self: 'mgr; + + type SyncWithConfigFuture<'mgr>: future::Future> + + Send + + Unpin + + 'mgr + where + Self: 'mgr; + fn get_config(&self, domain: &domain::Name) -> Result; - fn get_origin( - &self, - domain: &domain::Name, - ) -> Result, GetOriginError>; + fn get_origin(&self, domain: &domain::Name) -> Result, GetOriginError>; fn sync(&self, domain: &domain::Name) -> Result<(), SyncError>; fn sync_with_config( &self, domain: domain::Name, config: config::Config, - ) -> pin::Pin> + Send + '_>>; + ) -> Self::SyncWithConfigFuture<'_>; } pub trait BoxedManager: Manager + Send + Sync + Clone {} @@ -170,21 +182,24 @@ where OriginStore: origin::store::BoxedStore, DomainConfigStore: config::BoxedStore, { + type Origin<'mgr> = OriginStore::Origin<'mgr> + where Self: 'mgr; + + type SyncWithConfigFuture<'mgr> = pin::Pin> + Send + 'mgr>> + where Self: 'mgr; + fn get_config(&self, domain: &domain::Name) -> Result { Ok(self.domain_config_store.get(domain)?) } - fn get_origin( - &self, - domain: &domain::Name, - ) -> Result, GetOriginError> { + fn get_origin(&self, domain: &domain::Name) -> Result, GetOriginError> { let config = self.domain_config_store.get(domain)?; let origin = self .origin_store .get(config.origin_descr) // if there's a config there should be an origin, any error here is unexpected .map_err(|e| GetOriginError::Unexpected(Box::from(e)))?; - Ok(Box::from(origin)) + Ok(origin) } fn sync(&self, domain: &domain::Name) -> Result<(), SyncError> { @@ -202,7 +217,7 @@ where &self, domain: domain::Name, config: config::Config, - ) -> pin::Pin> + Send + '_>> { + ) -> Self::SyncWithConfigFuture<'_> { Box::pin(async move { let config_hash = config .hash() diff --git a/src/service.rs b/src/service.rs index 773234d..d528268 100644 --- a/src/service.rs +++ b/src/service.rs @@ -7,6 +7,7 @@ use std::net; use std::str::FromStr; use std::sync; +use crate::origin::Origin; use crate::{domain, origin}; pub mod http_tpl;