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

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

Useful for constructing notes from in-memory strings (e.g. in tests). For file-backed notes prefer Note::from_path.

Source

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.

Source

pub fn text(&self) -> &str

The entire, exact contents of the note including frontmatter.

Source

pub fn body(&self) -> &str

The note’s body — its contents with the frontmatter block stripped.

Returned as a zero-copy slice of text.

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.

Source

pub fn add_alias(&mut self, alias: String) -> Result<(), NoteError>

Add an alias, keeping text in sync.

Source

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

Add a frontmatter tag, keeping text in sync.

Source

pub fn remove_tag(&mut self, tag: &str) -> Result<(), NoteError>

Remove a frontmatter tag, keeping text in sync.

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.

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 the note to self.path, reconstructing the file from the in-memory text. Retained as a distinct entry point for frontmatter-only updates; with text as the source of truth it is equivalent to write.

Source

pub fn read(&self, include_frontmatter: bool) -> Result<String, NoteError>

Read the contents of the note as a string, optionally including frontmatter.

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 (const: unstable) · 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 = !

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.