pub struct TopicLoader { /* private fields */ }Expand description
Enumerator + reader/writer for topic .md files under a single memory
directory.
Implementations§
Source§impl TopicLoader
impl TopicLoader
Sourcepub fn new(dir: impl Into<PathBuf>) -> Self
pub fn new(dir: impl Into<PathBuf>) -> Self
Construct a loader over the given memory directory. The directory does
not have to exist yet — list returns an empty vec, and write will
create it on demand.
Sourcepub fn list(&self) -> Result<Vec<TopicSummary>>
pub fn list(&self) -> Result<Vec<TopicSummary>>
Enumerate every .md sibling of MEMORY.md, parsing frontmatter for
each. Files with malformed frontmatter are silently skipped with a
warn! log entry (rationale: a single corrupted topic file should not
brick the whole memory tier).
§Errors
Returns MemoryError::Io if the directory exists but cannot be read.
Sourcepub fn read(&self, name: &str) -> Result<TopicFile>
pub fn read(&self, name: &str) -> Result<TopicFile>
Read a topic by slug. The slug must pass validate_slug — no path
separators, no .., no leading ..
§Errors
Returns MemoryError::InvalidSlug for traversal / illegal slugs,
MemoryError::Io if the file does not exist or cannot be read, and
MemoryError::InvalidTopic if the frontmatter is malformed.
Sourcepub fn write(&self, draft: &TopicDraft) -> Result<PathBuf>
pub fn write(&self, draft: &TopicDraft) -> Result<PathBuf>
Atomically write a topic file (<slug>.md) and update the MEMORY.md
index line for it. Returns the topic’s absolute path on success.
Write semantics:
- Write the topic body + frontmatter to
<slug>.md.tmp. - Rename to
<slug>.md(atomic on the same filesystem). - Rewrite
MEMORY.mdwith an updated index line for the slug (MEMORY.mdis rewritten via the same tmp+rename dance).
A crash between (2) and (3) leaves an orphan topic file that
rebuild-index can re-detect.
§Errors
Returns MemoryError::InvalidSlug for bad slugs, MemoryError::Io
on any IO failure.
Sourcepub fn delete(&self, name: &str) -> Result<()>
pub fn delete(&self, name: &str) -> Result<()>
Delete a topic file by slug and remove its MEMORY.md index line.
Missing files are treated as success (idempotent delete).
§Errors
Returns MemoryError::InvalidSlug for bad slugs or MemoryError::Io
on IO failure.
Trait Implementations§
Source§impl Clone for TopicLoader
impl Clone for TopicLoader
Source§fn clone(&self) -> TopicLoader
fn clone(&self) -> TopicLoader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more