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§
Required Methods§
Sourcefn properties(&self) -> Result<Option<Cow<'_, Self::Properties>>, Self::Error>
fn properties(&self) -> Result<Option<Cow<'_, Self::Properties>>, Self::Error>
Returns the parsed properties of frontmatter
Returns None if the note has no properties
Provided Methods§
Sourcefn count_words_from_content(&self) -> Result<usize, Self::Error>
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);Sourcefn count_symbols_from_content(&self) -> Result<usize, Self::Error>
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.