Use GATs in domain manager trait
This commit is contained in:
parent
cab7a837a7
commit
45597ab8d8
@ -1,7 +1,8 @@
|
|||||||
use crate::domain::{self, checker, config};
|
use crate::domain::{self, checker, config};
|
||||||
use crate::origin;
|
use crate::origin;
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::future::Future;
|
use std::future;
|
||||||
use std::{pin, sync};
|
use std::{pin, sync};
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
@ -113,19 +114,30 @@ impl From<config::SetError> for SyncWithConfigError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[mockall::automock]
|
//#[mockall::automock(
|
||||||
|
// type Origin=origin::MockOrigin;
|
||||||
|
// type SyncWithConfigFuture=future::Ready<Result<(), SyncWithConfigError>>;
|
||||||
|
//)]
|
||||||
pub trait Manager {
|
pub trait Manager {
|
||||||
|
type Origin<'mgr>: origin::Origin + 'mgr
|
||||||
|
where
|
||||||
|
Self: 'mgr;
|
||||||
|
|
||||||
|
type SyncWithConfigFuture<'mgr>: future::Future<Output = Result<(), SyncWithConfigError>>
|
||||||
|
+ Send
|
||||||
|
+ Unpin
|
||||||
|
+ 'mgr
|
||||||
|
where
|
||||||
|
Self: 'mgr;
|
||||||
|
|
||||||
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError>;
|
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError>;
|
||||||
fn get_origin(
|
fn get_origin(&self, domain: &domain::Name) -> Result<Self::Origin<'_>, GetOriginError>;
|
||||||
&self,
|
|
||||||
domain: &domain::Name,
|
|
||||||
) -> Result<Box<dyn origin::Origin + '_>, GetOriginError>;
|
|
||||||
fn sync(&self, domain: &domain::Name) -> Result<(), SyncError>;
|
fn sync(&self, domain: &domain::Name) -> Result<(), SyncError>;
|
||||||
fn sync_with_config(
|
fn sync_with_config(
|
||||||
&self,
|
&self,
|
||||||
domain: domain::Name,
|
domain: domain::Name,
|
||||||
config: config::Config,
|
config: config::Config,
|
||||||
) -> pin::Pin<Box<dyn Future<Output = Result<(), SyncWithConfigError>> + Send + '_>>;
|
) -> Self::SyncWithConfigFuture<'_>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait BoxedManager: Manager + Send + Sync + Clone {}
|
pub trait BoxedManager: Manager + Send + Sync + Clone {}
|
||||||
@ -170,21 +182,24 @@ where
|
|||||||
OriginStore: origin::store::BoxedStore,
|
OriginStore: origin::store::BoxedStore,
|
||||||
DomainConfigStore: config::BoxedStore,
|
DomainConfigStore: config::BoxedStore,
|
||||||
{
|
{
|
||||||
|
type Origin<'mgr> = OriginStore::Origin<'mgr>
|
||||||
|
where Self: 'mgr;
|
||||||
|
|
||||||
|
type SyncWithConfigFuture<'mgr> = pin::Pin<Box<dyn future::Future<Output = Result<(), SyncWithConfigError>> + Send + 'mgr>>
|
||||||
|
where Self: 'mgr;
|
||||||
|
|
||||||
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError> {
|
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError> {
|
||||||
Ok(self.domain_config_store.get(domain)?)
|
Ok(self.domain_config_store.get(domain)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_origin(
|
fn get_origin(&self, domain: &domain::Name) -> Result<Self::Origin<'_>, GetOriginError> {
|
||||||
&self,
|
|
||||||
domain: &domain::Name,
|
|
||||||
) -> Result<Box<dyn origin::Origin + '_>, GetOriginError> {
|
|
||||||
let config = self.domain_config_store.get(domain)?;
|
let config = self.domain_config_store.get(domain)?;
|
||||||
let origin = self
|
let origin = self
|
||||||
.origin_store
|
.origin_store
|
||||||
.get(config.origin_descr)
|
.get(config.origin_descr)
|
||||||
// if there's a config there should be an origin, any error here is unexpected
|
// if there's a config there should be an origin, any error here is unexpected
|
||||||
.map_err(|e| GetOriginError::Unexpected(Box::from(e)))?;
|
.map_err(|e| GetOriginError::Unexpected(Box::from(e)))?;
|
||||||
Ok(Box::from(origin))
|
Ok(origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync(&self, domain: &domain::Name) -> Result<(), SyncError> {
|
fn sync(&self, domain: &domain::Name) -> Result<(), SyncError> {
|
||||||
@ -202,7 +217,7 @@ where
|
|||||||
&self,
|
&self,
|
||||||
domain: domain::Name,
|
domain: domain::Name,
|
||||||
config: config::Config,
|
config: config::Config,
|
||||||
) -> pin::Pin<Box<dyn Future<Output = Result<(), SyncWithConfigError>> + Send + '_>> {
|
) -> Self::SyncWithConfigFuture<'_> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let config_hash = config
|
let config_hash = config
|
||||||
.hash()
|
.hash()
|
||||||
|
@ -7,6 +7,7 @@ use std::net;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync;
|
use std::sync;
|
||||||
|
|
||||||
|
use crate::origin::Origin;
|
||||||
use crate::{domain, origin};
|
use crate::{domain, origin};
|
||||||
|
|
||||||
pub mod http_tpl;
|
pub mod http_tpl;
|
||||||
|
Loading…
Reference in New Issue
Block a user