pub struct Vault { /* private fields */ }Implementations§
Source§impl Vault
impl Vault
Sourcepub fn open(vault: Option<&Path>) -> Result<Self>
pub fn open(vault: Option<&Path>) -> Result<Self>
Resolve a vault (default location when vault is None) and load its
config. Does not create directories — call Self::ensure_initialized
for that.
Sourcepub fn with_config<R>(&self, f: impl FnOnce(&VaultConfig) -> R) -> R
pub fn with_config<R>(&self, f: impl FnOnce(&VaultConfig) -> R) -> R
Read config under a read guard. Use Self::categories when you only
need the list of categories — that helper already takes the guard and
clones for you.
Sourcepub fn categories(&self) -> Vec<CategoryDef>
pub fn categories(&self) -> Vec<CategoryDef>
Snapshot of the current category list (cloned under the read guard).
Sourcepub fn create_category(
&self,
id: String,
color: Option<String>,
) -> Result<CategoryDef>
pub fn create_category( &self, id: String, color: Option<String>, ) -> Result<CategoryDef>
Create a user-defined category. id is normalized (trimmed + lowercased);
rejects empty ids and collisions (including the built-in inbox).
color = None picks the first unused entry from AUTO_COLORS.
Sourcepub fn update_category(&self, id: String, color: String) -> Result<()>
pub fn update_category(&self, id: String, color: String) -> Result<()>
Update an existing category’s color. Errors if the id doesn’t match any
known category. inbox (and any other built-in) can be re-colored; only
deletion is restricted.
Sourcepub fn delete_category(&self, id: String) -> Result<()>
pub fn delete_category(&self, id: String) -> Result<()>
Remove a user-defined category. The built-in inbox cannot be deleted.
pub fn paths(&self) -> &Paths
Sourcepub fn ensure_initialized(&self) -> Result<()>
pub fn ensure_initialized(&self) -> Result<()>
Create the vault + index directories if missing.
Sourcepub fn save_asset(&self, bytes: &[u8], ext: &str) -> Result<AssetRef>
pub fn save_asset(&self, bytes: &[u8], ext: &str) -> Result<AssetRef>
Persist raw image bytes as a content-addressed asset and return the
oximg:// reference to drop into markdown. Identical bytes dedup to
the same file (no rewrite). ext is normalized + whitelisted.
Sourcepub fn save_asset_from_path(&self, src: &Path) -> Result<AssetRef>
pub fn save_asset_from_path(&self, src: &Path) -> Result<AssetRef>
Read an image from an arbitrary path (file-picker) and store it. The extension is taken from the source filename.
Sourcepub fn read_asset(&self, name: &str) -> Option<(Vec<u8>, &'static str)>
pub fn read_asset(&self, name: &str) -> Option<(Vec<u8>, &'static str)>
Serve an asset’s bytes + content-type for the oximg:// handler.
Returns None if the name is malformed or the file is absent.
Sourcepub fn list_assets(&self) -> Result<Vec<AssetInfo>>
pub fn list_assets(&self) -> Result<Vec<AssetInfo>>
All assets on disk, newest-first (gallery). Cheap: a single dir read.
Sourcepub fn gc_assets(&self) -> Result<u64>
pub fn gc_assets(&self) -> Result<u64>
Delete assets referenced by no live memo. Returns the count removed. Scans every memo body, so call from an explicit user action (gallery “clean up”), not a hot path.
Sourcepub fn find_memo_by_asset(&self, name: &str) -> Result<Option<MemoId>>
pub fn find_memo_by_asset(&self, name: &str) -> Result<Option<MemoId>>
First live memo whose body references asset name, or None. Powers
the gallery’s “open the memo containing this image”.
pub fn create_memo( &self, body: String, category: Option<String>, ) -> Result<Memo>
pub fn get_memo(&self, id: MemoId) -> Result<Memo>
pub fn update_memo( &self, id: MemoId, body: Option<String>, favorite: Option<bool>, category: Option<String>, ) -> Result<Memo>
Sourcepub fn delete_memo(&self, id: MemoId) -> Result<()>
pub fn delete_memo(&self, id: MemoId) -> Result<()>
Soft-delete: move to trash, mark tombstone, drop from search (§5.4).
pub fn restore_memo(&self, id: MemoId) -> Result<Memo>
Sourcepub fn purge(&self, retention: Duration) -> Result<u64>
pub fn purge(&self, retention: Duration) -> Result<u64>
Hard-delete trashed memos whose deleted_at is older than retention.
Returns the number purged.
pub fn list_memos( &self, after: Option<Cursor>, limit: u32, filter: MemoFilter, ) -> Result<Page<MemoSummary>>
pub fn search_memos(&self, query: &str, limit: u32) -> Result<Vec<MemoSummary>>
pub fn get_note_summary(&self, id: MemoId) -> Result<MemoSummary>
Sourcepub fn memo_stats(&self) -> Result<MemoStats>
pub fn memo_stats(&self) -> Result<MemoStats>
Live note counts (soft-deleted tombstones excluded).
Sourcepub fn list_facets(&self) -> Result<Facets>
pub fn list_facets(&self) -> Result<Facets>
Tag + color counts over live (non-deleted) notes for the sidebar (§4.2).
pub fn export_manifest( &self, since: Option<OffsetDateTime>, ) -> Result<Vec<ManifestRecord>>
pub fn export_full(&self, ids: &[MemoId]) -> Result<Vec<FullRecord>>
Sourcepub fn reindex(&self) -> Result<IndexStats>
pub fn reindex(&self) -> Result<IndexStats>
Rebuild the indexes from the source-of-truth files (§5.5, §9.1).
Sourcepub fn migrate(&self) -> Result<()>
pub fn migrate(&self) -> Result<()>
One-time migrations run on first use:
- Rename the live memo tree from
notes/tomemos/if the legacy path is non-empty and the new one is absent. - Rebuild the index when the cached preview format lags the current
make_preview(or the marker is absent), so existing memos’ card previews pick up line-break preservation.
Idempotent: subsequent calls are no-ops once both markers are current.
Sourcepub fn reindex_path(&self, path: &Path)
pub fn reindex_path(&self, path: &Path)
Re-index a single changed file. Called by the watcher (debounced). Handles create/modify (upsert) and removal (delete from index + search).
Sourcepub fn watch(&self) -> Result<MemoWatcher>
pub fn watch(&self) -> Result<MemoWatcher>
Start the background file watcher (§5.5). The returned handle must be kept alive for the lifetime of the watch.
Sourcepub fn doctor(&self, fix: bool) -> Result<DoctorReport>
pub fn doctor(&self, fix: bool) -> Result<DoctorReport>
Consistency check (§9.3). When fix is true, safe repairs are applied
(hash recompute + rewrite; orphan index cleanup). Files are never deleted.
Sourcepub fn rename_category(&self, old: String, new: String) -> Result<u64>
pub fn rename_category(&self, old: String, new: String) -> Result<u64>
Rename a category, migrating every note whose category matches old
to new. Each migrated note is rewritten (category, updated_at, hash),
re-added to the redb index and the tantivy search index, and the
category registry is updated and persisted. Returns the number of
notes migrated.
Rules:
oldandneware normalized (trimmed + lowercased).- Neither side may be the built-in
inbox(immutable). oldmust exist in the registry;newmust not collide.old == newis rejected.
Auto Trait Implementations§
impl !Freeze for Vault
impl !RefUnwindSafe for Vault
impl Send for Vault
impl Sync for Vault
impl Unpin for Vault
impl UnsafeUnpin for Vault
impl UnwindSafe for Vault
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more