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