opys_engine/backend.rs
1//! The storage backend seam.
2//!
3//! A [`Backend`] is the durable medium the corpus lives in: it loads documents
4//! into the in-memory working [`Store`] and flushes the store's net changes
5//! back. Commands operate on the core `Store` and never touch the medium
6//! directly — they go through the injected backend, so the medium is swappable.
7//!
8//! [`MarkdownLocal`] is the default (and, today, only) implementation: one
9//! markdown file per document in a local-filesystem inventory. Other media (a
10//! database, a remote service) would be alternative `Backend` impls, selected by
11//! the binary.
12
13use crate::error::Result;
14use crate::project::Project;
15use crate::store::Store;
16
17/// A durable storage medium for the corpus.
18pub trait Backend {
19 /// Load the durable corpus into a fresh working [`Store`], plus non-fatal
20 /// parse errors (unparsable documents are skipped, not fatal).
21 fn load(&self, prj: &Project) -> Result<(Store, Vec<String>)>;
22
23 /// Persist the store's net changes: write changed documents, delete removed
24 /// ones, relocate moved ones, and rewrite the retired-id ledger.
25 fn flush(&self, prj: &Project, store: Store) -> Result<()>;
26
27 /// Read and parse every durable document (raw, without building a store),
28 /// returning parsed docs + non-fatal parse errors. Used by read-only passes
29 /// (stats, history) and the TUI board.
30 fn load_docs(&self, prj: &Project) -> (Vec<crate::doc::Doc>, Vec<String>);
31}