pub trait ObFile<T = HashMap<String, Value>>: Sizedwhere
T: DeserializeOwned + Clone,{
// Required methods
fn content(&self) -> Result<Cow<'_, str>, Error>;
fn path(&self) -> Option<Cow<'_, Path>>;
fn properties(&self) -> Result<Option<Cow<'_, T>>, Error>;
fn from_string<P: AsRef<Path>>(
raw_text: &str,
path: Option<P>,
) -> Result<Self, Error>;
// Provided methods
fn note_name(&self) -> Option<String> { ... }
fn from_file<P: AsRef<Path>>(path: P) -> Result<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.
§Type Parameters
T: Frontmatter properties type
§Example
use obsidian_parser::prelude::*;
use serde::Deserialize;
#[derive(Deserialize, Clone)]
struct NoteProperties {
topic: String,
created: String,
}
let note: ObFileInMemory<NoteProperties> = ObFile::from_file("note.md").unwrap();
let properties = note.properties().unwrap().unwrap();
println!("Note topic: {}", properties.topic);Required Methods§
Sourcefn path(&self) -> Option<Cow<'_, Path>>
fn path(&self) -> Option<Cow<'_, Path>>
Returns the source file path if available
Returns None for in-memory notes without physical storage
Sourcefn from_string<P: AsRef<Path>>(
raw_text: &str,
path: Option<P>,
) -> Result<Self, Error>
fn from_string<P: AsRef<Path>>( raw_text: &str, path: Option<P>, ) -> Result<Self, Error>
Parses an Obsidian note from a string
§Arguments
raw_text: Raw markdown content with optional YAML frontmatterpath: Optional source path for reference
§Errors
Error::InvalidFormatfor malformed frontmatterError::Yamlfor invalid YAML syntax
Provided Methods§
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.