Trait ObFile

Source
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 implement DeserializeOwned + 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§

Source

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
Source

fn path(&self) -> Option<PathBuf>

Returns the source file path if available

Returns None for in-memory notes without physical storage

Source

fn properties(&self) -> T

Returns parsed frontmatter properties

§Behavior
  • Returns default-initialized properties if frontmatter is missing/invalid
  • Automatically handles YAML deserialization
Source

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 frontmatter
  • path: Optional source path for reference
§Errors
  • Error::InvalidFormat for malformed frontmatter
  • Error::Yaml for invalid YAML syntax

Provided Methods§

Source

fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Parses an Obsidian note from a file

§Arguments
  • path: Filesystem path to markdown file
§Errors
  • Error::Io for filesystem errors
  • Error::FromUtf8 for non-UTF8 content

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§