Skip to main content

DocumentLoader

Trait DocumentLoader 

Source
pub trait DocumentLoader: Send + Sync {
    // Required methods
    fn supported_extensions(&self) -> Vec<&str>;
    fn load(&self, path: &Path) -> Result<Document>;

    // Provided method
    fn can_load(&self, path: &Path) -> bool { ... }
}
Expand description

Abstraction for loading files of any format into Documents.

Implementors handle format detection, parsing, and conversion to the standard Document representation. A loader may support multiple file extensions.

Required Methods§

Source

fn supported_extensions(&self) -> Vec<&str>

File extensions this loader handles (lowercase, without dot).

Source

fn load(&self, path: &Path) -> Result<Document>

Load a file and produce a Document.

The returned Document should have:

  • content: The extracted text
  • source: The file path
  • title: Derived from filename or embedded metadata
  • metadata: Format-specific fields

Provided Methods§

Source

fn can_load(&self, path: &Path) -> bool

Returns true if this loader can handle the given path.

Default implementation checks the file extension against supported_extensions().

Implementors§