processors_rs/
processor.rs1use std::path::Path;
2
3pub trait DocumentProcessor {
4
5 fn process_document(&self, content: &str) -> anyhow::Result<Document>;
6}
7
8pub trait FileProcessor {
9
10 fn process_file(&self, path: impl AsRef<Path>) -> anyhow::Result<Document>;
11}
12
13pub trait UrlProcessor {
14 fn process_url(&self, url: &str) -> anyhow::Result<Document>;
15}
16
17impl <T: DocumentProcessor> FileProcessor for T {
18 fn process_file(&self, path: impl AsRef<Path>) -> anyhow::Result<Document> {
19 let bytes = std::fs::read(path)?;
20 let out = String::from_utf8_lossy(&bytes);
21 self.process_document(&out)
22 }
23}
24
25impl <T: DocumentProcessor> UrlProcessor for T {
26 fn process_url(&self, url: &str) -> anyhow::Result<Document> {
27 let content = reqwest::blocking::get(url)?.text()?;
28 self.process_document(&content)
29 }
30}
31
32pub struct Document {
33 pub chunks: Vec<String>
34}