Skip to main content

VaultPath

Struct VaultPath 

Source
pub struct VaultPath { /* private fields */ }
Expand description

A logical, vault-internal path to a note or directory.

VaultPath is the core’s single currency for everything inside a vault: it never refers to a location outside the workspace, and it is portable across Windows, macOS, and Linux. Components are sanitized and lowercased on construction (see VaultPath::new) so that only characters valid on all three filesystems survive and equality is effectively case-insensitive. The separator is always PATH_SEPARATOR (/); translation to native OS paths happens only at the filesystem boundary in nfs.

A path may be absolute (rooted at the vault root, rendered with a leading /) or relative, and may contain ./.. components until flattened.

Implementations§

Source§

impl VaultPath

Source

pub fn new<S: AsRef<str>>(path: S) -> Self

Creates a new vault path, for every invalid character it gets replaced to an underscore _. If you want to validate the path first, either use the VaultPath::From trait or use VaultPath::is_valid()

Source

pub fn is_valid<S: AsRef<str>>(path: S) -> bool

Returns true if path is already a clean vault path needing no sanitization: every component is valid on all three target filesystems and there are no doubled separators. Use this to validate caller-supplied strings up front; VaultPath::new will instead silently repair them.

use kimun_core::nfs::VaultPath;
assert!(VaultPath::is_valid("/projects/notes.md"));
assert!(!VaultPath::is_valid("bad?name"));
Source

pub fn note_path_from<S: AsRef<str>>(path: S) -> Self

Builds a sanitized note path from path, ensuring it ends with the note extension. A trailing separator is dropped before the extension is added, so notes/ becomes notes.md. Unlike with_note_extension, the rest of the string is sanitized through VaultPath::new, so this is the correct constructor for real note paths (not search patterns).

use kimun_core::nfs::VaultPath;
assert_eq!(VaultPath::note_path_from("projects/todo").to_string(), "projects/todo.md");
assert_eq!(VaultPath::note_path_from("readme.md").to_string(), "readme.md");
Source

pub fn root() -> Self

The vault root: an absolute path with no components, rendered as /.

use kimun_core::nfs::VaultPath;
assert_eq!(VaultPath::root().to_string(), "/");
Source

pub fn empty() -> Self

The empty relative path: no components and not absolute, rendered as the empty string. Distinct from root, which is absolute.

use kimun_core::nfs::VaultPath;
assert_eq!(VaultPath::empty().to_string(), "");
Source

pub fn is_root_or_empty(&self) -> bool

Returns true when the path has no components, i.e. it is either the vault root or the empty path.

Source

pub fn get_name_on_conflict(&self) -> VaultPath

Returns a variant of this path with its final component’s name incremented to avoid a collision. A numeric _N suffix is added or bumped (e.g. note.mdnote_0.md, note_0.mdnote_1.md), preserving the note extension. Used to pick a fresh name when the desired one is taken.

Source

pub fn get_clean_name(&self) -> String

Returns the final component’s name with the note extension stripped — the note’s display title as derived from its filename. For directories (no extension) this is just the directory name. Compare get_name, which keeps the extension.

use kimun_core::nfs::VaultPath;
assert_eq!(VaultPath::new("/projects/todo.md").get_clean_name(), "todo");
Source

pub fn to_bare_string(&self) -> String

Returns the full vault path as a string with the note extension stripped. E.g. /projects/rust-notes.md/projects/rust-notes If the path does not end with the note extension, returns it unchanged.

Source

pub fn to_string_with_ext(&self) -> String

Returns the full vault path as a string, ensuring it ends with the note extension. E.g. /projects/rust-notes/projects/rust-notes.md If the path already ends with the extension, returns it unchanged.

Source

pub fn get_slices(&self) -> Vec<String>

Returns the path’s components as plain strings, after flattening (so no ./.. entries remain). Useful for walking the path level by level.

use kimun_core::nfs::VaultPath;
assert_eq!(VaultPath::new("/a/b/c.md").get_slices(), vec!["a", "b", "c.md"]);
Source

pub fn to_pathbuf<P: AsRef<Path>>(&self, workspace_path: P) -> PathBuf

Joins this path onto workspace_path to produce the canonical on-disk PathBuf, mapping / to native separators and flattening first.

This is the canonical (lowercase) location only; it does not perform case-insensitive resolution, so an existing file stored under a different case will not be found. Use the nfs resolver for that.

Source

pub fn flatten(&self) -> VaultPath

Returns a full path without any relative slices If it tries to go up beyond the current path, drops a warning

Source

pub fn get_name(&self) -> String

Returns the last part of the path slices if it is a note, will return the note filename, if it is a directory, will return the directory name

Returns the path of self written relative to a note file’s directory.

Markdown engines resolve relative links against the containing folder, not the note file itself. Linking from /notes/journal/today.md to /assets/img.png therefore produces ../../assets/img.png (two ..s — for journal/ and notes/), not three. This wraps Self::get_relative_to using the note’s parent path so callers get the markdown-correct result.

Resolve self as a link target written inside note_path.

Inverse of Self::relative_link_from_note: markdown links resolve against the directory containing the note, so a ../work/anton.md target in /journal/today.md resolves to /work/anton.md (flattened, absolute). Absolute targets are returned flattened as-is. A bare filename with no directory part (e.g. anton.md) is returned unchanged so callers can fall back to a vault-wide name lookup (wiki-style links).

Source

pub fn get_relative_to(&self, reference_path: &VaultPath) -> VaultPath

Expresses this path relative to reference_path, walking up with .. for each component of the reference not shared with this path, then down into this path’s remaining components. The result is always relative.

Note reference_path is treated as a directory: every one of its trailing components becomes a ... To build a markdown link relative to a note file, use relative_link_from_note, which accounts for the note’s own filename.

use kimun_core::nfs::VaultPath;
let from = VaultPath::new("/main/path/first");
let target = VaultPath::new("/main/second");
assert_eq!(target.get_relative_to(&from).to_string(), "../../second");
Source

pub fn from_path<P: AsRef<Path>, F: AsRef<Path>>( workspace_path: P, full_path: F, ) -> Result<Self, FSError>

Converts a real on-disk path back into an absolute vault path by stripping the workspace_path prefix. Returns FSError::InvalidPath if full_path does not live inside the workspace. Each OS component is run through VaultPath::new, so the result is sanitized and lowercased.

Source

pub fn is_note_file(&self) -> bool

Returns true if this path is a bare note filename: a single, relative component ending in the note extension, with no directory part (e.g. anton.md). Such paths are the signal for a vault-wide, wiki-style name lookup rather than a directory-scoped path match.

use kimun_core::nfs::VaultPath;
assert!(VaultPath::new("anton.md").is_note_file());
assert!(!VaultPath::new("/work/anton.md").is_note_file());
Source

pub fn is_note(&self) -> bool

Returns true if this path points at a note, i.e. its final component ends with the note extension. Unlike is_note_file, the path may have any number of directory components.

Source

pub fn ensure_note(&self) -> Result<(), FSError>

Returns Ok if the path looks like a note path; otherwise an InvalidPath error.

Source

pub fn ensure_directory(&self) -> Result<(), FSError>

Returns Ok if the path does not have a note extension; otherwise an InvalidPath error.

Source

pub fn is_relative(&self) -> bool

Returns true if this path is relative (not rooted at the vault root).

Source

pub fn is_absolute(&self) -> bool

Returns true if this path is absolute (rooted at the vault root).

Source

pub fn to_absolute(&mut self)

Marks this path absolute in place.

Source

pub fn absolute(self) -> Self

Consumes the path and returns it marked absolute (builder-style sibling of to_absolute).

Source

pub fn to_relative(&mut self)

Marks this path relative in place.

Source

pub fn get_parent_path(&self) -> (VaultPath, String)

Splits the path into its parent path and the final component’s name. The parent keeps this path’s absoluteness; the name is the empty string when the path has no components.

use kimun_core::nfs::VaultPath;
let (parent, name) = VaultPath::new("/a/b/c.md").get_parent_path();
assert_eq!(parent.to_string(), "/a/b");
assert_eq!(name, "c.md");
Source

pub fn append(&self, path: &VaultPath) -> VaultPath

Appends path to this one. If path is absolute it wins outright and is returned as-is; otherwise its components are concatenated onto this path, keeping this path’s absoluteness. The result is not flattened, so any .. in path survives until flatten is called.

use kimun_core::nfs::VaultPath;
let base = VaultPath::new("/main/path");
let rel = VaultPath::new("sub/note.md");
assert_eq!(base.append(&rel).to_string(), "/main/path/sub/note.md");
Source

pub fn is_like(&self, other: &VaultPath) -> bool

Compares two paths by components only, ignoring whether each is absolute or relative. So /a/b is “like” a/b.

use kimun_core::nfs::VaultPath;
assert!(VaultPath::new("/a/b").is_like(&VaultPath::new("a/b")));

Trait Implementations§

Source§

impl Clone for VaultPath

Source§

fn clone(&self) -> VaultPath

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VaultPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for VaultPath

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for VaultPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for VaultPath

Source§

impl From<&VaultPath> for VaultPath

Source§

fn from(value: &VaultPath) -> Self

Converts to this type from the input type.
Source§

impl FromStr for VaultPath

Source§

type Err = FSError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for VaultPath

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for VaultPath

Source§

fn cmp(&self, other: &VaultPath) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for VaultPath

Source§

fn eq(&self, other: &VaultPath) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for VaultPath

Source§

fn partial_cmp(&self, other: &VaultPath) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for VaultPath

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for VaultPath

Source§

impl TryFrom<&String> for VaultPath

Source§

type Error = FSError

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

fn try_from(value: &String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for VaultPath

Source§

type Error = FSError

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

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for VaultPath

Source§

type Error = FSError

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

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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