use std::future::Future;
use std::pin::Pin;
use crate::domain::subject::Subject;
pub const NOT_SUPPORTED: &str = "storage control not supported by this substrate";
#[derive(Clone, Debug)]
pub struct StorageOpts {
pub size_mb: u64,
pub mount: String,
}
impl StorageOpts {
pub fn validate(&self) -> Result<(), String> {
if self.size_mb == 0 {
return Err("storage: size_mb must be > 0".to_string());
}
if !self.mount.starts_with('/') {
return Err("storage: mount must be an absolute path".to_string());
}
Ok(())
}
}
pub trait StorageControl: Send + Sync + 'static {
fn set_seed(&self, _seed: u64) {}
fn attach<'a>(
&'a self,
_subject: &'a Subject,
_opts: StorageOpts,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> {
Box::pin(async move { Err(NOT_SUPPORTED.to_string()) })
}
fn error<'a>(
&'a self,
_subject: &'a Subject,
_on: bool,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> {
Box::pin(async move { Err(NOT_SUPPORTED.to_string()) })
}
fn drop_writes<'a>(
&'a self,
_subject: &'a Subject,
_on: bool,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> {
Box::pin(async move { Err(NOT_SUPPORTED.to_string()) })
}
fn slow<'a>(
&'a self,
_subject: &'a Subject,
_delay_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> {
Box::pin(async move { Err(NOT_SUPPORTED.to_string()) })
}
fn corrupt<'a>(
&'a self,
_subject: &'a Subject,
_n: u64,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> {
Box::pin(async move { Err(NOT_SUPPORTED.to_string()) })
}
fn snapshot<'a>(
&'a self,
_subject: &'a Subject,
) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send + 'a>> {
Box::pin(async move { Err(NOT_SUPPORTED.to_string()) })
}
fn restore<'a>(
&'a self,
_subject: &'a Subject,
_snapshot_id: &'a str,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> {
Box::pin(async move { Err(NOT_SUPPORTED.to_string()) })
}
}