You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
use futures::stream::BoxStream; |
|
|
|
use crate::common::{ |
|
entities::{DecodedValue, Dict, DictEntry, EncodedValue}, |
|
errors::{CodecError, RepositoryError}, |
|
}; |
|
|
|
pub trait SystemDecoder: Send + Sync { |
|
fn decode(&self, word: &str) -> Result<DecodedValue, CodecError>; |
|
} |
|
|
|
pub trait SystemEncoder: Send + Sync { |
|
fn initialize(&self) -> Result<(), CodecError>; |
|
fn encode(&self, word: &str) -> Result<EncodedValue, CodecError>; |
|
} |
|
|
|
#[async_trait::async_trait] |
|
pub trait DictRepository: Send + Sync { |
|
fn use_dict(&mut self, name: &str); |
|
async fn create_dict(&self) -> Result<(), RepositoryError>; |
|
|
|
/// "Upsert" logic: |
|
/// - If entry exists (by text), update metadata. |
|
/// - If not, insert new. |
|
/// - IDs are handled by the Database. |
|
async fn save_entries(&self, entries: &[DictEntry]) -> Result<(), RepositoryError>; |
|
|
|
/// Fetch a page of entries. |
|
async fn fetch_many(&self, limit: usize, offset: usize) -> Result<Dict, RepositoryError>; |
|
|
|
/// Returns a cold stream that fetches strings in chunks. |
|
/// The stream yields `Result<Vec<String>, RepositoryError>`. |
|
async fn stream_batches( |
|
&self, |
|
batch_size: usize, |
|
) -> Result<BoxStream<'_, Result<Vec<String>, RepositoryError>>, RepositoryError>; |
|
} |
|
|
|
pub trait DictSource { |
|
fn next_entry(&mut self) -> Option<Result<DictEntry, anyhow::Error>>; |
|
}
|
|
|