Trait ObFile

Source
pub trait ObFile<T = HashMap<String, Value>>: Sized{
    // 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§

Source

fn content(&self) -> Result<Cow<'_, str>, Error>

Returns the main content body of the note (excluding frontmatter)

§Implementation Notes
  • Strips YAML frontmatter if present
  • Preserves original formatting and whitespace
§Errors

Usually errors are related to Error::Io

Source

fn path(&self) -> Option<Cow<'_, Path>>

Returns the source file path if available

Returns None for in-memory notes without physical storage

Source

fn properties(&self) -> Result<Option<Cow<'_, T>>, Error>

Returns the parsed properties of frontmatter

Returns None if the note has no properties

§Errors

Usually errors are related to Error::Io

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

Provided Methods§

Source

fn note_name(&self) -> Option<String>

Get note name

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

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§