weavatrix_memory/extraction/
provider.rs1use super::{ExtractionInput, ExtractionOutput};
2use std::{error::Error, fmt};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct ExtractionError {
6 pub provider: String,
7 pub message: String,
8}
9
10impl ExtractionError {
11 #[must_use]
12 pub fn new(provider: impl Into<String>, message: impl Into<String>) -> Self {
13 Self {
14 provider: provider.into(),
15 message: message.into(),
16 }
17 }
18}
19
20impl fmt::Display for ExtractionError {
21 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
22 write!(
23 formatter,
24 "extraction provider {} failed: {}",
25 self.provider, self.message
26 )
27 }
28}
29
30impl Error for ExtractionError {}
31
32pub trait ExtractionProvider: Sync {
38 fn name(&self) -> &str;
39
40 fn extract(&self, input: &ExtractionInput) -> Result<ExtractionOutput, ExtractionError>;
47}