#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[allow(dead_code)]
pub(crate) struct DownloadProgress {
enabled: bool,
}
#[allow(dead_code)]
impl DownloadProgress {
pub(crate) const SILENT: Self = Self { enabled: false };
pub(crate) const fn new(enabled: bool) -> Self {
Self { enabled }
}
pub(crate) const fn is_enabled(self) -> bool {
self.enabled
}
}
impl From<&super::processing::EmbeddingConfig> for DownloadProgress {
fn from(config: &super::processing::EmbeddingConfig) -> Self {
Self::new(config.show_download_progress)
}
}
impl From<&super::sparse_embedding::SparseEmbeddingConfig> for DownloadProgress {
fn from(config: &super::sparse_embedding::SparseEmbeddingConfig) -> Self {
Self::new(config.show_download_progress)
}
}
impl From<&super::reranker::RerankerConfig> for DownloadProgress {
fn from(config: &super::reranker::RerankerConfig) -> Self {
Self::new(config.show_download_progress)
}
}
impl From<&super::late_interaction::LateInteractionConfig> for DownloadProgress {
fn from(config: &super::late_interaction::LateInteractionConfig) -> Self {
Self::new(config.show_download_progress)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::core::config::late_interaction::LateInteractionConfig;
use crate::core::config::processing::EmbeddingConfig;
use crate::core::config::reranker::RerankerConfig;
use crate::core::config::sparse_embedding::SparseEmbeddingConfig;
#[test]
fn silent_is_disabled_and_is_the_default() {
assert!(!DownloadProgress::SILENT.is_enabled());
assert_eq!(DownloadProgress::default(), DownloadProgress::SILENT);
}
#[test]
fn new_round_trips_the_flag() {
assert!(DownloadProgress::new(true).is_enabled());
assert!(!DownloadProgress::new(false).is_enabled());
}
#[test]
fn embedding_config_show_download_progress_reaches_the_download_layer() {
for requested in [true, false] {
let config = EmbeddingConfig {
show_download_progress: requested,
..Default::default()
};
assert_eq!(
DownloadProgress::from(&config),
DownloadProgress::new(requested),
"EmbeddingConfig::show_download_progress={requested} must reach the download layer"
);
}
}
#[test]
fn sparse_embedding_config_show_download_progress_reaches_the_download_layer() {
for requested in [true, false] {
let config = SparseEmbeddingConfig {
show_download_progress: requested,
..Default::default()
};
assert_eq!(
DownloadProgress::from(&config),
DownloadProgress::new(requested),
"SparseEmbeddingConfig::show_download_progress={requested} must reach the download layer"
);
}
}
#[test]
fn reranker_config_show_download_progress_reaches_the_download_layer() {
for requested in [true, false] {
let config = RerankerConfig {
show_download_progress: requested,
..Default::default()
};
assert_eq!(
DownloadProgress::from(&config),
DownloadProgress::new(requested),
"RerankerConfig::show_download_progress={requested} must reach the download layer"
);
}
}
#[test]
fn late_interaction_config_show_download_progress_reaches_the_download_layer() {
for requested in [true, false] {
let config = LateInteractionConfig {
show_download_progress: requested,
..Default::default()
};
assert_eq!(
DownloadProgress::from(&config),
DownloadProgress::new(requested),
"LateInteractionConfig::show_download_progress={requested} must reach the download layer"
);
}
}
}