pub struct Note {
pub path: PathBuf,
pub id: String,
pub title: Option<String>,
pub aliases: Vec<String>,
pub tags: Vec<LocatedTag>,
pub links: Vec<LocatedLink>,
pub frontmatter: Option<IndexMap<String, Pod>>,
pub frontmatter_line_count: usize,
/* private fields */
}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.
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.
Useful for constructing notes from in-memory strings (e.g. in tests). For file-backed
notes prefer Note::from_path.
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, retaining the full contents in Note::text.
Links and inline tags are extracted and stored. Note the entire file is read and retained in memory.
Sourcepub fn body(&self) -> &str
pub fn body(&self) -> &str
The note’s body — its contents with the frontmatter block stripped.
Returned as a zero-copy slice of text.
pub fn update_content( &mut self, body: Option<&str>, frontmatter: Option<IndexMap<String, Pod>>, ) -> Result<(), NoteError>
Sourcepub fn add_alias(&mut self, alias: String) -> Result<(), NoteError>
pub fn add_alias(&mut self, alias: String) -> Result<(), NoteError>
Add an alias, keeping text in sync.
Sourcepub fn add_tag(&mut self, tag: impl Into<String>) -> Result<(), NoteError>
pub fn add_tag(&mut self, tag: impl Into<String>) -> Result<(), NoteError>
Add a frontmatter tag, keeping text in sync.
Sourcepub fn remove_tag(&mut self, tag: &str) -> Result<(), NoteError>
pub fn remove_tag(&mut self, tag: &str) -> Result<(), NoteError>
Remove a frontmatter tag, keeping text in sync.
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.
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>
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.
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