Skip to main content

Vault

Struct Vault 

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

Implementations§

Source§

impl Vault

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, VaultError>

Opens a vault at the given path, returning an error if the path does not exist or is not a directory.

Source

pub fn open_from_cwd() -> Result<Self, VaultError>

Opens the nearest vault by walking up from the current directory, looking for an .obsidian/ directory. Falls back to the current directory if none is found.

Source

pub fn path(&self) -> &Path

Source

pub fn resolve_note(&self, note: &str) -> Result<Note, VaultError>

Resolve a note based on a path, filename, ID, title, or alias.

Source

pub fn resolve_note_path( &self, path: impl AsRef<Path>, strict: bool, ) -> Result<(PathBuf, Option<PathBuf>), VaultError>

Resolve a note path argument, which may be absolute or relative to either the current working directory or the vault root. Returns the resolved absolute path and the root it was resolved against, if any.

Source

pub fn notes(&self) -> Vec<Result<Note, NoteError>>

Loads all notes in the vault in parallel, without retaining body content.

Links and inline tags are still extracted and available on each note. Use notes_with_content when body text is needed.

Source

pub fn notes_with_content(&self) -> Vec<Result<Note, NoteError>>

Like notes, but retains body content in each [Note::content].

Source

pub fn load_note(&mut self, note: Note)

Inserts or replaces an in-memory note. While present, this note shadows its on-disk counterpart (matched by note.path) across all vault search operations. Notes with a path that does not exist on disk are included as additional candidates.

Source

pub fn unload_note(&mut self, path: &Path)

Removes a previously loaded in-memory note, restoring the on-disk version for searches. Does nothing if the path is not currently loaded.

Source

pub fn note_is_loaded(&self, path: impl AsRef<Path>) -> bool

Source

pub fn notes_filtered( &self, filter: impl Fn(&Path) -> bool, ) -> Vec<Result<Note, NoteError>>

Like notes, but skips notes whose path does not satisfy filter. Filtering happens at the filesystem traversal level, before any file is read.

Source

pub fn notes_filtered_with_content( &self, filter: impl Fn(&Path) -> bool, ) -> Vec<Result<Note, NoteError>>

Like notes_filtered, but retains body content in each [Note::content].

Source

pub fn search(&self) -> SearchQuery<'_>

Returns a SearchQuery rooted at this vault’s path. Any notes previously registered via load_note are automatically included, shadowing their on-disk counterparts.

Source

pub fn list_tags(&self) -> Result<Vec<String>, VaultError>

Returns all unique tags used in the vault, aggregated from frontmatter and inline tags.

Source

pub fn find_tags( &self, tags: &[String], ) -> Result<Vec<(Note, Vec<LocatedTag>)>, VaultError>

Find all occurrences of specific tags, grouped by the note they appear in. Tags are matched case-insensitively, and sub-tags are gathered as well.

Source

pub fn rename_tag( &mut self, old_tag: &str, new_tag: &str, ) -> Result<Vec<(Note, Vec<LocatedTag>)>, VaultError>

Find and replaces all occurrences of old_tag with the new new_tag and return the occurrences and location of the new tag.

Returns all notes in the vault that link to target, paired with the specific LocatedLinks within each note that point to it.

Only wiki links ([[target]]) and markdown links ([text](target.md)) are considered. Embed links are excluded. Notes that fail to load are silently skipped.

Like backlinks, but operates on an already-loaded slice of notes instead of reading from disk. Returns references into notes.

Source

pub fn rename( &mut self, note: &Note, new_path: &Path, ) -> Result<Note, VaultError>

Renames note to new_path (full destination path), updating all backlinks.

Wiki links targeting the old ID are rewritten to the new stem. Markdown links pointing to the old path are rewritten to the new path. Wiki links targeting an alias are left unchanged. Returns the reloaded Note at the new path.

Returns VaultError::DirectoryNotFound if the parent directory of new_path does not exist, and VaultError::NoteAlreadyExists if new_path is already occupied.

Source

pub fn rename_preview( &self, note: &Note, new_path: &Path, ) -> Result<RenamePreview, VaultError>

Returns a preview of what rename would change without touching the filesystem.

Same validation and error variants as rename.

Source

pub fn patch_note( &mut self, note: &Note, old_string: &str, new_string: &str, ) -> Result<Note, VaultError>

Replaces the first (and only) occurrence of old_string in the raw file content of note with new_string, writing the result back to disk.

Returns VaultError::StringNotFound if old_string does not appear in the file, and VaultError::StringFoundMultipleTimes if it appears more than once. Both checks operate on the raw file bytes (frontmatter included).

Source

pub fn merge( &mut self, sources: &[Note], dest_path: &impl AsRef<Path>, ) -> Result<Note, VaultError>

Merges sources into dest_path: appends each source’s body to the destination, union-merges tags and aliases, rewrites all backlinks to sources in other notes to point to the destination, and deletes the source files.

The destination is created if it doesn’t exist, or its content is appended to if it does. Returns the resulting destination Note.

Source

pub fn merge_preview( &self, sources: &[Note], dest_path: impl AsRef<Path>, ) -> Result<MergePreview, VaultError>

Returns a preview of what merge would change without touching the filesystem.

Same validation and error variants as merge.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.