use std::future::Future;
use std::pin::Pin;
use crate::error::{DeployError, ProviderError};
use crate::invoke::{InvokeRequest, InvokeResponse};
use crate::types::{Capabilities, DeploymentRef, DeploymentSpec, Endpoint, ReleaseMode, ReplicaRef, ReplicaState};
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub trait Provider: Send + Sync {
fn capabilities(&self) -> Capabilities;
fn wake<'a>(
&'a self,
deployment: &'a DeploymentRef,
replicas: u32,
) -> BoxFuture<'a, Result<Vec<Endpoint>, ProviderError>>;
fn release<'a>(&'a self, replica: &'a ReplicaRef, mode: ReleaseMode) -> BoxFuture<'a, Result<(), ProviderError>>;
fn list<'a>(&'a self, deployment: &'a DeploymentRef) -> BoxFuture<'a, Result<Vec<ReplicaState>, ProviderError>>;
fn invoke<'a>(
&'a self,
_endpoint: &'a Endpoint,
_request: InvokeRequest,
) -> Option<BoxFuture<'a, Result<InvokeResponse, ProviderError>>> {
None
}
}
pub trait DeployDriver: Send + Sync {
fn apply<'a>(&'a self, spec: &'a DeploymentSpec) -> BoxFuture<'a, Result<DeploymentRef, DeployError>>;
}
impl<P: Provider + ?Sized> Provider for std::sync::Arc<P> {
fn capabilities(&self) -> Capabilities {
(**self).capabilities()
}
fn wake<'a>(
&'a self,
deployment: &'a DeploymentRef,
replicas: u32,
) -> BoxFuture<'a, Result<Vec<Endpoint>, ProviderError>> {
(**self).wake(deployment, replicas)
}
fn release<'a>(&'a self, replica: &'a ReplicaRef, mode: ReleaseMode) -> BoxFuture<'a, Result<(), ProviderError>> {
(**self).release(replica, mode)
}
fn list<'a>(&'a self, deployment: &'a DeploymentRef) -> BoxFuture<'a, Result<Vec<ReplicaState>, ProviderError>> {
(**self).list(deployment)
}
fn invoke<'a>(
&'a self,
endpoint: &'a Endpoint,
request: InvokeRequest,
) -> Option<BoxFuture<'a, Result<InvokeResponse, ProviderError>>> {
(**self).invoke(endpoint, request)
}
}