Skip to main content

Vault

Struct Vault 

Source
pub struct Vault { /* private fields */ }

Implementations§

Source§

impl Vault

Source

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.

Source

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.

Source

pub fn categories(&self) -> Vec<CategoryDef>

Snapshot of the current category list (cloned under the read guard).

Source

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.

Source

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.

Source

pub fn delete_category(&self, id: String) -> Result<()>

Remove a user-defined category. The built-in inbox cannot be deleted.

Source

pub fn paths(&self) -> &Paths

Source

pub fn ensure_initialized(&self) -> Result<()>

Create the vault + index directories if missing.

Source

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.

Source

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.

Source

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.

Source

pub fn list_assets(&self) -> Result<Vec<AssetInfo>>

All assets on disk, newest-first (gallery). Cheap: a single dir read.

Source

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.

Source

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”.

Source

pub fn create_memo( &self, body: String, category: Option<String>, ) -> Result<Memo>

Source

pub fn get_memo(&self, id: MemoId) -> Result<Memo>

Source

pub fn update_memo( &self, id: MemoId, body: Option<String>, favorite: Option<bool>, category: Option<String>, ) -> Result<Memo>

Source

pub fn delete_memo(&self, id: MemoId) -> Result<()>

Soft-delete: move to trash, mark tombstone, drop from search (§5.4).

Source

pub fn restore_memo(&self, id: MemoId) -> Result<Memo>

Source

pub fn purge(&self, retention: Duration) -> Result<u64>

Hard-delete trashed memos whose deleted_at is older than retention. Returns the number purged.

Source

pub fn list_memos( &self, after: Option<Cursor>, limit: u32, filter: MemoFilter, ) -> Result<Page<MemoSummary>>

Source

pub fn search_memos(&self, query: &str, limit: u32) -> Result<Vec<MemoSummary>>

Source

pub fn get_note_summary(&self, id: MemoId) -> Result<MemoSummary>

Source

pub fn memo_stats(&self) -> Result<MemoStats>

Live note counts (soft-deleted tombstones excluded).

Source

pub fn list_facets(&self) -> Result<Facets>

Tag + color counts over live (non-deleted) notes for the sidebar (§4.2).

Source

pub fn export_manifest( &self, since: Option<OffsetDateTime>, ) -> Result<Vec<ManifestRecord>>

Source

pub fn export_full(&self, ids: &[MemoId]) -> Result<Vec<FullRecord>>

Source

pub fn reindex(&self) -> Result<IndexStats>

Rebuild the indexes from the source-of-truth files (§5.5, §9.1).

Source

pub fn migrate(&self) -> Result<()>

One-time migrations run on first use:

  1. Rename the live memo tree from notes/ to memos/ if the legacy path is non-empty and the new one is absent.
  2. 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.

Source

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).

Source

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.

Source

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.

Source

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:

  • old and new are normalized (trimmed + lowercased).
  • Neither side may be the built-in inbox (immutable).
  • old must exist in the registry; new must not collide.
  • old == new is rejected.
Source

pub fn reset(&self) -> Result<()>

Wipe all memos, trash, and the derived redb + tantivy indexes, returning the vault to an empty state. The source-of-truth .md files (live + trash) are deleted and both indexes are cleared. Category/color config is preserved. Backs the settings “reset” action.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Fruit for T
where T: Send + Downcast,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more