use std::future::Future;
use std::pin::Pin;
use crate::error::Result;
use super::CheckpointState;
pub trait Checkpoint: Send + Sync {
fn save(&self, state: &CheckpointState) -> impl Future<Output = Result<()>> + Send;
fn load(&self, run_id: &str) -> impl Future<Output = Result<Option<CheckpointState>>> + Send;
fn list_runs(&self) -> impl Future<Output = Result<Vec<String>>> + Send;
fn delete(&self, run_id: &str) -> impl Future<Output = Result<()>> + Send;
}
pub trait ErasedCheckpoint: Send + Sync {
fn save_erased<'a>(
&'a self,
state: &'a CheckpointState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
fn load_erased<'a>(
&'a self,
run_id: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<CheckpointState>>> + Send + 'a>>;
fn list_runs_erased(&self) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + '_>>;
fn delete_erased<'a>(
&'a self,
run_id: &'a str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
}
impl<T: Checkpoint> ErasedCheckpoint for T {
fn save_erased<'a>(
&'a self,
state: &'a CheckpointState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> {
Box::pin(self.save(state))
}
fn load_erased<'a>(
&'a self,
run_id: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<CheckpointState>>> + Send + 'a>> {
Box::pin(self.load(run_id))
}
fn list_runs_erased(&self) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + '_>> {
Box::pin(self.list_runs())
}
fn delete_erased<'a>(
&'a self,
run_id: &'a str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> {
Box::pin(self.delete(run_id))
}
}