pub trait ObFile<T = HashMap<String, Value>>: Sizedwhere
T: DeserializeOwned + Clone,{
// Required methods
fn content(&self) -> String;
fn path(&self) -> Option<PathBuf>;
fn properties(&self) -> Option<T>;
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, Default, Clone)]
struct NoteProperties {
topic: String,
created: String,
}
let note: ObFileInMemory<NoteProperties> = ObFile::from_file("note.md").unwrap();
println!("Note topic: {}", note.properties().unwrap().topic);Required Methods§
Sourcefn content(&self) -> String
fn content(&self) -> String
Returns the main content body of the note (excluding frontmatter)
§Implementation Notes
- Strips YAML frontmatter if present
- Preserves original formatting and whitespace
Sourcefn path(&self) -> Option<PathBuf>
fn path(&self) -> Option<PathBuf>
Returns the source file path if available
Returns None for in-memory notes without physical storage
Sourcefn properties(&self) -> Option<T>
fn properties(&self) -> Option<T>
Returns the parsed properties of frontmatter
Returns None if the note has no properties
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.