use diskann::ANNResult;
#[cfg(all(not(miri), target_os = "linux"))]
use super::LinuxAlignedFileReader;
#[cfg(any(miri, target_os = "macos"))]
use super::StorageProviderAlignedFileReader;
#[cfg(all(not(miri), target_os = "windows"))]
use super::WindowsAlignedFileReader;
use crate::utils::aligned_file_reader::traits::AlignedReaderFactory;
#[cfg(any(miri, target_os = "macos"))]
use diskann_providers::storage::FileStorageProvider;
pub struct AlignedFileReaderFactory {
pub file_path: String,
}
impl AlignedReaderFactory for AlignedFileReaderFactory {
#[cfg(any(miri, target_os = "macos"))]
type AlignedReaderType = StorageProviderAlignedFileReader;
#[cfg(all(not(miri), target_os = "linux"))]
type AlignedReaderType = LinuxAlignedFileReader;
#[cfg(all(not(miri), target_os = "windows"))]
type AlignedReaderType = WindowsAlignedFileReader;
fn build(&self) -> ANNResult<Self::AlignedReaderType> {
#[cfg(any(miri, target_os = "macos"))]
return StorageProviderAlignedFileReader::new(
&FileStorageProvider,
self.file_path.as_str(),
);
#[cfg(all(not(miri), target_os = "windows"))]
return WindowsAlignedFileReader::new(self.file_path.as_str());
#[cfg(all(not(miri), target_os = "linux"))]
return LinuxAlignedFileReader::new(self.file_path.as_str());
}
}
impl AlignedFileReaderFactory {
pub fn new(file_path: String) -> Self {
Self { file_path }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_aligned_file_reader_factory_new() {
let path = "/tmp/test.bin".to_string();
let factory = AlignedFileReaderFactory::new(path.clone());
assert_eq!(factory.file_path, path);
}
}