use std::sync::Arc;
use async_trait::async_trait;
use crate::BoxliteResult;
use crate::volumes::VolumeInfo;
#[async_trait]
pub(crate) trait VolumeBackend: Send + Sync {
async fn create_volume(&self, name: Option<&str>) -> BoxliteResult<VolumeInfo>;
async fn list_volumes(&self) -> BoxliteResult<Vec<VolumeInfo>>;
async fn get_volume(&self, id: &str) -> BoxliteResult<VolumeInfo>;
async fn remove_volume(&self, id: &str, force: bool) -> BoxliteResult<()>;
}
#[derive(Clone)]
pub struct VolumeHandle {
backend: Arc<dyn VolumeBackend>,
}
impl VolumeHandle {
pub(crate) fn new(backend: Arc<dyn VolumeBackend>) -> Self {
Self { backend }
}
pub async fn create(&self, name: Option<&str>) -> BoxliteResult<VolumeInfo> {
self.backend.create_volume(name).await
}
pub async fn list(&self) -> BoxliteResult<Vec<VolumeInfo>> {
self.backend.list_volumes().await
}
pub async fn get(&self, id: &str) -> BoxliteResult<VolumeInfo> {
self.backend.get_volume(id).await
}
pub async fn remove(&self, id: &str, force: bool) -> BoxliteResult<()> {
self.backend.remove_volume(id, force).await
}
}