Skip to main content

Note

Struct Note 

Source
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>§tags: Vec<LocatedTag>

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: usize

Number 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

Source

pub fn builder(path: impl AsRef<Path>) -> Result<NoteBuilder, NoteError>

Source

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).

Source

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).

Source

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.

Source

pub fn update_content( &mut self, body: Option<&str>, frontmatter: Option<IndexMap<String, Pod>>, ) -> Result<(), NoteError>

Source

pub fn reload(self) -> Result<Self, NoteError>

Reloads the note from its path without retaining body content.

Source

pub fn reload_with_body(self) -> Result<Self, NoteError>

Reloads the note from its path while retaining body content.

Source

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.

Source

pub fn add_alias(&mut self, alias: String)

Add an alias.

Source

pub fn add_tag(&mut self, tag: impl Into<String>)

Add a frontmatter tag.

Source

pub fn remove_tag(&mut self, tag: &str)

Remove a frontmatter tag.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn frontmatter_map(&self) -> IndexMap<String, Pod>

Get the note’s frontmatter map.

Source

pub fn frontmatter_yaml(&self) -> Result<Mapping, Error>

Get the note’s frontmatter map in a form suitable for YAML serialization.

Source

pub fn frontmatter_json(&self) -> Result<Map<String, Value>, NoteError>

Get the note’s frontmatter map in a form suitable for JSON serialization.

Source

pub fn frontmatter_string(&self) -> Result<String, Error>

Get the note’s frontmatter as a YAML string (without delimiters).

Source

pub fn last_modified_time(&self) -> SystemTime

Get the last modified time of the note’s file on disk.

Source

pub fn creation_time(&self) -> SystemTime

Get the creation time of the note.

Trait Implementations§

Source§

impl Clone for Note

Source§

fn clone(&self) -> Note

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

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> 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> 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<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> 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, 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.