pub struct Vault { /* private fields */ }Implementations§
Source§impl Vault
impl Vault
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, VaultError>
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.
Sourcepub fn open_from_cwd() -> Result<Self, VaultError>
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.
pub fn path(&self) -> &Path
Sourcepub fn resolve_note(&self, note: &str) -> Result<Note, VaultError>
pub fn resolve_note(&self, note: &str) -> Result<Note, VaultError>
Resolve a note based on a path, filename, ID, title, or alias.
Sourcepub fn resolve_note_path(
&self,
path: impl AsRef<Path>,
strict: bool,
) -> Result<(PathBuf, Option<PathBuf>), VaultError>
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.
Sourcepub fn notes(&self) -> Vec<Result<Note, NoteError>>
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.
Sourcepub fn notes_with_content(&self) -> Vec<Result<Note, NoteError>>
pub fn notes_with_content(&self) -> Vec<Result<Note, NoteError>>
Like notes, but retains body content in each [Note::content].
Sourcepub fn load_note(&mut self, note: Note)
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.
Sourcepub fn unload_note(&mut self, path: &Path)
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.
pub fn note_is_loaded(&self, path: impl AsRef<Path>) -> bool
Sourcepub fn notes_filtered(
&self,
filter: impl Fn(&Path) -> bool,
) -> Vec<Result<Note, NoteError>>
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.
Sourcepub fn notes_filtered_with_content(
&self,
filter: impl Fn(&Path) -> bool,
) -> Vec<Result<Note, NoteError>>
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].
Sourcepub fn search(&self) -> SearchQuery<'_>
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.
Returns all unique tags used in the vault, aggregated from frontmatter and inline tags.
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.
Sourcepub fn rename_tag(
&mut self,
old_tag: &str,
new_tag: &str,
) -> Result<Vec<(Note, Vec<LocatedTag>)>, VaultError>
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.
Sourcepub fn backlinks(
&self,
target: &Note,
) -> Result<Vec<(Note, Vec<LocatedLink>)>, VaultError>
pub fn backlinks( &self, target: &Note, ) -> Result<Vec<(Note, Vec<LocatedLink>)>, VaultError>
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.
Sourcepub fn backlinks_from<'a>(
&self,
notes: &'a [Note],
target: &Note,
) -> Vec<(&'a Note, Vec<LocatedLink>)>
pub fn backlinks_from<'a>( &self, notes: &'a [Note], target: &Note, ) -> Vec<(&'a Note, Vec<LocatedLink>)>
Like backlinks, but operates on an already-loaded slice of notes
instead of reading from disk. Returns references into notes.
Sourcepub fn rename(
&mut self,
note: &Note,
new_path: &Path,
) -> Result<Note, VaultError>
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.
Sourcepub fn rename_preview(
&self,
note: &Note,
new_path: &Path,
) -> Result<RenamePreview, VaultError>
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.
Sourcepub fn patch_note(
&mut self,
note: &Note,
old_string: &str,
new_string: &str,
) -> Result<Note, VaultError>
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).
Sourcepub fn merge(
&mut self,
sources: &[Note],
dest_path: &impl AsRef<Path>,
) -> Result<Note, VaultError>
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.
Sourcepub fn merge_preview(
&self,
sources: &[Note],
dest_path: impl AsRef<Path>,
) -> Result<MergePreview, VaultError>
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> 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> 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