pub trait ObFile<T = HashMap<String, Value>>: Sized{
// Required methods
fn content(&self) -> String;
fn path(&self) -> Option<PathBuf>;
fn properties(&self) -> T;
fn from_string<P: AsRef<Path>>(
raw_text: &str,
path: Option<P>,
) -> Result<Self, Error>;
// Provided method
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 (must implementDeserializeOwned + Default + Clone + Send)
§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().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) -> T
fn properties(&self) -> T
Returns parsed frontmatter properties
§Behavior
- Returns default-initialized properties if frontmatter is missing/invalid
- Automatically handles YAML deserialization
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.