use anyhow::Result;
use nuts_storable::Value;
use crate::{Math, Progress, Settings};
pub trait ChainStorage: Send {
type Finalized: Send + Sync + 'static;
fn record_sample(
&mut self,
settings: &impl Settings,
stats: Vec<(&str, Option<Value>)>,
draws: Vec<(&str, Option<Value>)>,
info: &Progress,
) -> Result<()>;
fn finalize(self) -> Result<Self::Finalized>;
fn inspect(&self) -> Result<Option<Self::Finalized>> {
Ok(None)
}
fn flush(&self) -> Result<()>;
}
pub trait StorageConfig: Send + 'static {
type Storage: TraceStorage;
fn new_trace<M: Math>(self, settings: &impl Settings, math: &M) -> Result<Self::Storage>;
}
pub trait TraceStorage: Send + Sync + Sized + 'static {
type ChainStorage: ChainStorage;
type Finalized: Send + Sync + 'static;
fn initialize_trace_for_chain(&self, chain_id: u64) -> Result<Self::ChainStorage>;
fn finalize(
self,
traces: Vec<Result<<Self::ChainStorage as ChainStorage>::Finalized>>,
) -> Result<(Option<anyhow::Error>, Self::Finalized)>;
fn inspect(
&self,
traces: Vec<Result<Option<<Self::ChainStorage as ChainStorage>::Finalized>>>,
) -> Result<(Option<anyhow::Error>, Self::Finalized)>;
}