1use std::path::Path;
2use super::{Document, Id};
3
4pub trait DocumentLoad {
5 type Error: std::error::Error + 'static + Send + Sync;
6 fn load<P>(&self, path: P) -> Result<Document, Self::Error>
7 where
8 P: AsRef<Path>;
9}
10
11pub struct TextLoader;
12
13impl DocumentLoad for TextLoader {
14 type Error = std::io::Error;
15
16 fn load<P>(&self, path: P) -> Result<Document, Self::Error>
17 where
18 P: AsRef<Path>
19 {
20 let path = path.as_ref();
21 let text = std::fs::read_to_string(path)?;
22 Ok(Document { id: Id::uuid(), source: path.to_path_buf(), text })
23 }
24}