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.
 
 
 

47 lines
1.3 KiB

use crate::core::entities::EncodingResult;
use crate::core::errors::EncoderError;
use super::entities::{Dict, DictEntry};
use super::errors::RepositoryError;
/// The number value can be encoded as many word sets,
/// but decoded as one number. For partial values, we can use
/// u64, but for the whole decoded value that may be very long,
/// we need a string.
type DecodedValue = String;
pub trait SystemDecoder {
fn decode(&self, word: &str) -> DecodedValue;
}
pub trait SystemEncoder {
fn initialize(&self) -> Result<(), EncoderError>;
fn encode(&self, word: &str) -> Result<EncodingResult, EncoderError>;
}
#[async_trait::async_trait]
pub trait DictRepository: Send + Sync {
async fn create_dict(&self, name: &str) -> 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,
dict_name: &str,
entries: &[DictEntry],
) -> Result<(), RepositoryError>;
/// Fetch a page of entries.
async fn fetch_many(
&self,
name: &str,
limit: Option<u32>,
offset: Option<u32>,
) -> Result<Dict, RepositoryError>;
}
pub trait DictSource {
fn next_entry(&mut self) -> Option<Result<DictEntry, anyhow::Error>>;
}