Skip to main content

create_note

Function create_note 

Source
pub fn create_note<T: AsRef<Path>>(path: T, name: &str) -> Result<Note, Error>
Expand description

Creates a new empty note with the provided name.

If a note with the given name already exists, a numbered suffix will be appended (e.g., “Note 1”, “Note 2”, etc.) to find an available name.

§Errors

Returns an error if:

  • I/O operations fail (directory creation, file writing, or path checks)
  • No available name is found after 999 attempts (Error::MaxAttemptsExceeded)

§Examples

let vault = Vault { path: tmp_path.to_path_buf(), ..Default::default() };
let note = obsidian::vault::create_note(vault.path, "/notes/Arbitrary Name")?;
assert_eq!(note.name(), "Arbitrary Name");
assert_eq!(note.path(), tmp_path.join("notes/Arbitrary Name.md"));
assert_eq!(fs::exists(note.path())?, true);