Skip to main content

vectrust_storage/
backend.rs

1use std::path::Path;
2use vectrust_core::*;
3
4pub struct Storage;
5
6impl Storage {
7    /// Auto-detect storage format and return appropriate backend
8    pub fn auto_detect(path: &Path, index_name: &str) -> Result<Box<dyn StorageBackend>> {
9        let index_path = path.join(index_name);
10        let manifest_path = path.join("manifest.json");
11        
12        if manifest_path.exists() {
13            // V2 optimized format
14            Ok(Box::new(crate::OptimizedStorage::new(path)?))
15        } else if index_path.exists() {
16            // V1 legacy format
17            Ok(Box::new(crate::LegacyStorage::new(path, index_name)?))
18        } else {
19            // New index - use optimized format
20            Ok(Box::new(crate::OptimizedStorage::new(path)?))
21        }
22    }
23}