Note

Trait Note 

Source
pub trait Note: Sized {
    type Properties: Clone;
    type Error: Error;

    // Required methods
    fn properties(
        &self,
    ) -> Result<Option<Cow<'_, Self::Properties>>, Self::Error>;
    fn content(&self) -> Result<Cow<'_, str>, Self::Error>;
    fn path(&self) -> Option<Cow<'_, Path>>;

    // Provided methods
    fn note_name(&self) -> Option<String> { ... }
    fn count_words_from_content(&self) -> Result<usize, Self::Error> { ... }
    fn count_symbols_from_content(&self) -> Result<usize, Self::Error> { ... }
}
Expand description

Represents an Obsidian note file with frontmatter properties and content

This trait provides a standardized interface for working with Obsidian markdown files, handling frontmatter parsing, content extraction, and file operations.

§Example

use obsidian_parser::prelude::*;
use serde::Deserialize;

#[derive(Deserialize, Clone)]
struct NoteProperties {
    topic: String,
    created: String,
}

let note: NoteInMemory<NoteProperties> = NoteFromFile::from_file("note.md").unwrap();
let properties = note.properties().unwrap().unwrap();
println!("Note topic: {}", properties.topic);

§Other

Required Associated Types§

Source

type Properties: Clone

Frontmatter properties type

Source

type Error: Error

Error type

Required Methods§

Source

fn properties(&self) -> Result<Option<Cow<'_, Self::Properties>>, Self::Error>

Returns the parsed properties of frontmatter

Returns None if the note has no properties

Source

fn content(&self) -> Result<Cow<'_, str>, Self::Error>

Returns the main content body of the note (excluding frontmatter)

§Implementation Notes
  • Strips YAML frontmatter if present
  • Preserves original formatting and whitespace
Source

fn path(&self) -> Option<Cow<'_, Path>>

Returns the source file path if available

Returns None for in-memory notes without physical storage

Provided Methods§

Source

fn note_name(&self) -> Option<String>

Get note name

Source

fn count_words_from_content(&self) -> Result<usize, Self::Error>

Get count words from content

§Example
use obsidian_parser::prelude::*;

let data = "---\ntags:\n- my_tag\n---\n My super note";
let note = NoteInMemory::from_string_default(data).unwrap();

assert_eq!(note.count_words_from_content().unwrap(), 3);
Source

fn count_symbols_from_content(&self) -> Result<usize, Self::Error>

Get count symbols from content

§Example
use obsidian_parser::prelude::*;

let data = "---\ntags:\n- my_tag\n---\n My super note";
let content = "My super note";

let note = NoteInMemory::from_string_default(data).unwrap();

assert_eq!(note.count_symbols_from_content().unwrap(), content.len());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§