use async_trait::async_trait;
use serde_json::Value;
#[async_trait]
pub trait ProtocolStateExporter: Send + Sync {
fn protocol_name(&self) -> &str;
async fn export_state(&self) -> crate::Result<Value>;
async fn import_state(&self, state: Value) -> crate::Result<()>;
async fn state_summary(&self) -> String {
"state available".to_string()
}
}
pub struct BoxedStateExporter(pub Box<dyn ProtocolStateExporter>);
impl BoxedStateExporter {
pub fn new<T: ProtocolStateExporter + 'static>(exporter: T) -> Self {
Self(Box::new(exporter))
}
}
#[async_trait]
impl ProtocolStateExporter for BoxedStateExporter {
fn protocol_name(&self) -> &str {
self.0.protocol_name()
}
async fn export_state(&self) -> crate::Result<Value> {
self.0.export_state().await
}
async fn import_state(&self, state: Value) -> crate::Result<()> {
self.0.import_state(state).await
}
async fn state_summary(&self) -> String {
self.0.state_summary().await
}
}