mod freshness;
mod lifecycle;
mod read;
mod schema;
mod write;
pub use freshness::{CacheMiss, CorpusLookup, open_latest_fresh};
pub use lifecycle::{
CleanupEntry, CleanupMode, CleanupReport, cleanup, corpus_dir, index_path, latest_index_path, latest_name,
set_latest,
};
pub use read::Store;
pub use schema::STORE_SCHEMA_VERSION;
pub use write::{Ingest, StoreBuilder};
use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum StoreError {
Sqlite(rusqlite::Error),
Io(std::io::Error),
Json(serde_json::Error),
SchemaMismatch {
found: String,
expected: &'static str,
},
MissingMetadata(String),
Corrupt(&'static str),
Closed,
}
impl fmt::Display for StoreError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Sqlite(error) => write!(formatter, "sqlite error: {error}"),
Self::Io(error) => write!(formatter, "io error: {error}"),
Self::Json(error) => write!(formatter, "json error: {error}"),
Self::SchemaMismatch { found, expected } => {
write!(formatter, "store schema version {found} is not the expected {expected}")
}
Self::MissingMetadata(key) => write!(formatter, "store is missing required metadata: {key}"),
Self::Corrupt(key) => write!(formatter, "store metadata value is corrupt: {key}"),
Self::Closed => write!(formatter, "store builder has already been published"),
}
}
}
impl std::error::Error for StoreError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Sqlite(error) => Some(error),
Self::Io(error) => Some(error),
Self::Json(error) => Some(error),
Self::SchemaMismatch { .. } | Self::MissingMetadata(_) | Self::Corrupt(_) | Self::Closed => None,
}
}
}
impl From<rusqlite::Error> for StoreError {
fn from(error: rusqlite::Error) -> Self {
Self::Sqlite(error)
}
}
impl From<std::io::Error> for StoreError {
fn from(error: std::io::Error) -> Self {
Self::Io(error)
}
}
impl From<serde_json::Error> for StoreError {
fn from(error: serde_json::Error) -> Self {
Self::Json(error)
}
}