pub struct Note {
pub path: PathBuf,
pub id: String,
pub title: Option<String>,
pub aliases: Vec<String>,
pub tags: Vec<LocatedTag>,
pub body: Option<String>,
pub links: Vec<LocatedLink>,
pub frontmatter: Option<IndexMap<String, Pod>>,
pub frontmatter_line_count: usize,
}Fields§
§path: PathBuf§id: String§title: Option<String>§aliases: Vec<String>All tags: frontmatter tags have location: Location::Frontmatter; inline tags have
location: Location::Inline(...). Always populated, even when content is not loaded.
body: Option<String>Body text stripped of frontmatter. None when the note was loaded without body
(the default). Use Note::from_path_with_body or Note::load_body to
populate this field. Required for Note::write.
links: Vec<LocatedLink>Links extracted from the body at load time (always populated).
frontmatter: Option<IndexMap<String, Pod>>§frontmatter_line_count: usizeNumber of lines occupied by the frontmatter block (including delimiters). Used to offset link locations so they reflect positions in the original file.
Implementations§
Source§impl Note
impl Note
pub fn builder(path: impl AsRef<Path>) -> Result<NoteBuilder, NoteError>
Sourcepub fn parse(path: impl AsRef<Path>, content: &str) -> Self
pub fn parse(path: impl AsRef<Path>, content: &str) -> Self
Parses a note from a raw file string, always retaining the body content.
Useful for constructing notes from in-memory strings (e.g. in tests).
For file-backed notes prefer Note::from_path (no content) or
Note::from_path_with_body (with content).
Sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self, NoteError>
pub fn from_path(path: impl AsRef<Path>) -> Result<Self, NoteError>
Loads a note from disk without retaining the body content.
Links and inline tags are still extracted and stored. This is the
memory-efficient default for bulk operations. Use
from_path_with_body when the body
text is needed (e.g. for content search or writing).
Sourcepub fn from_path_with_body(path: impl AsRef<Path>) -> Result<Self, NoteError>
pub fn from_path_with_body(path: impl AsRef<Path>) -> Result<Self, NoteError>
Loads a note from disk, retaining the full body content in Note::body.
pub fn update_content( &mut self, body: Option<&str>, frontmatter: Option<IndexMap<String, Pod>>, ) -> Result<(), NoteError>
Sourcepub fn reload(self) -> Result<Self, NoteError>
pub fn reload(self) -> Result<Self, NoteError>
Reloads the note from its path without retaining body content.
Sourcepub fn reload_with_body(self) -> Result<Self, NoteError>
pub fn reload_with_body(self) -> Result<Self, NoteError>
Reloads the note from its path while retaining body content.
Sourcepub fn load_body(&mut self) -> Result<(), NoteError>
pub fn load_body(&mut self) -> Result<(), NoteError>
Populates Note::body by reading the note’s body from disk.
Does nothing if the body is already loaded.
Sourcepub fn remove_tag(&mut self, tag: &str)
pub fn remove_tag(&mut self, tag: &str)
Remove a frontmatter tag.
Sourcepub fn set_field(&mut self, key: &str, value: &Value) -> Result<(), NoteError>
pub fn set_field(&mut self, key: &str, value: &Value) -> Result<(), NoteError>
Set an arbitrary frontmatter field to a value (which can be any YAML type). A null value removes the field from the frontmatter.
Sourcepub fn write(&self) -> Result<(), NoteError>
pub fn write(&self) -> Result<(), NoteError>
Atomically writes the note to self.path, including serialized frontmatter.
Requires Note::body to be populated. Returns
NoteError::BodyNotLoaded if the body is None.
Frontmatter keys are serialized in a deterministic order: id first, then
title (if present), then aliases, then tags, then all remaining keys
sorted alphabetically.
Sourcepub fn write_frontmatter(&self) -> Result<(), NoteError>
pub fn write_frontmatter(&self) -> Result<(), NoteError>
Atomically writes updated frontmatter to self.path, reading the current body
from disk. Use this when only frontmatter has changed but not the body.
Sourcepub fn read(&self, include_frontmatter: bool) -> Result<String, NoteError>
pub fn read(&self, include_frontmatter: bool) -> Result<String, NoteError>
Read the contents of the note as a string, optionally including frontmatter.
Requires Note::body to be populated. Returns
NoteError::BodyNotLoaded if the body is None.
Sourcepub fn frontmatter_map(&self) -> IndexMap<String, Pod>
pub fn frontmatter_map(&self) -> IndexMap<String, Pod>
Get the note’s frontmatter map.
Sourcepub fn frontmatter_yaml(&self) -> Result<Mapping, Error>
pub fn frontmatter_yaml(&self) -> Result<Mapping, Error>
Get the note’s frontmatter map in a form suitable for YAML serialization.
Sourcepub fn frontmatter_json(&self) -> Result<Map<String, Value>, NoteError>
pub fn frontmatter_json(&self) -> Result<Map<String, Value>, NoteError>
Get the note’s frontmatter map in a form suitable for JSON serialization.
Sourcepub fn frontmatter_string(&self) -> Result<String, Error>
pub fn frontmatter_string(&self) -> Result<String, Error>
Get the note’s frontmatter as a YAML string (without delimiters).
Sourcepub fn last_modified_time(&self) -> SystemTime
pub fn last_modified_time(&self) -> SystemTime
Get the last modified time of the note’s file on disk.
Sourcepub fn creation_time(&self) -> SystemTime
pub fn creation_time(&self) -> SystemTime
Get the creation time of the note.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Note
impl RefUnwindSafe for Note
impl Send for Note
impl Sync for Note
impl Unpin for Note
impl UnsafeUnpin for Note
impl UnwindSafe for Note
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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