mod autosave;
mod memory;
#[cfg(not(target_arch = "wasm32"))]
mod file;
#[cfg(target_arch = "wasm32")]
mod indexeddb;
pub use autosave::{
AutoSaveManager,
PlatformAutoSaveManager,
PlatformStorage,
create_autosave_manager,
create_default_storage,
DEFAULT_AUTOSAVE_INTERVAL_SECS,
LAST_DOCUMENT_KEY,
};
pub use memory::MemoryStorage;
#[cfg(not(target_arch = "wasm32"))]
pub use file::FileStorage;
#[cfg(target_arch = "wasm32")]
pub use indexeddb::IndexedDbStorage;
use crate::canvas::CanvasDocument;
use std::future::Future;
use std::pin::Pin;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum StorageError {
#[error("Document not found: {0}")]
NotFound(String),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("IO error: {0}")]
Io(String),
#[error("Storage error: {0}")]
Other(String),
}
pub type StorageResult<T> = Result<T, StorageError>;
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
#[cfg(not(target_arch = "wasm32"))]
pub trait Storage: Send + Sync {
fn save(&self, id: &str, document: &CanvasDocument) -> BoxFuture<'_, StorageResult<()>>;
fn load(&self, id: &str) -> BoxFuture<'_, StorageResult<CanvasDocument>>;
fn delete(&self, id: &str) -> BoxFuture<'_, StorageResult<()>>;
fn list(&self) -> BoxFuture<'_, StorageResult<Vec<String>>>;
fn exists(&self, id: &str) -> BoxFuture<'_, StorageResult<bool>>;
}
#[cfg(target_arch = "wasm32")]
pub trait Storage {
fn save(&self, id: &str, document: &CanvasDocument) -> BoxFuture<'_, StorageResult<()>>;
fn load(&self, id: &str) -> BoxFuture<'_, StorageResult<CanvasDocument>>;
fn delete(&self, id: &str) -> BoxFuture<'_, StorageResult<()>>;
fn list(&self) -> BoxFuture<'_, StorageResult<Vec<String>>>;
fn exists(&self, id: &str) -> BoxFuture<'_, StorageResult<bool>>;
}