原文
Unified Traits, Different Implementations
Both browser and server implement the same storage traits:
trait DocumentStorage {
async fn save(&self, key: &str, data: &[u8]) -> Result<()>;
async fn load(&self, key: &str) -> Result<Option<Vec<u8>>>;
// ...
}
trait ChangeLog {
async fn append_change(&self, namespace_id: &str, change: Change) -> Result<()>;
async fn get_changes_since(&self, namespace_id: &str, since: i64) -> Result<Vec<Change>>;
// ...
} Browser: localStorage + IndexedDB implementations
Server: redb + memory implementations
Same workflows. Same APIs. Just different backends.