Factory function to create a storage driver based on configuration This is the main entry point for creating storage drivers. It takes a storage type and path, then returns the appropriate driver implementation as a trait object. # Arguments `storage_type` - The type of storage driver to create (Sled or Memory) `path` - The filesystem path where the database should be stored # Returns A boxed t
(
storage_type: StorageType,
path: P,
)
| 30 | /// let tree = driver.open_tree("my_tree")?; |
| 31 | /// ``` |
| 32 | pub fn create_storage_driver<P: AsRef<Path>>( |
| 33 | storage_type: StorageType, |
| 34 | path: P, |
| 35 | ) -> StorageResult<Box<dyn StorageDriver<Tree = Box<dyn StorageTree>>>> { |
| 36 | match storage_type { |
| 37 | StorageType::Sled => { |
| 38 | use crate::storage::persistent::sled::SledDriver; |
| 39 | let driver = SledDriver::open(path)?; |
| 40 | Ok(Box::new(driver) as Box<dyn StorageDriver<Tree = Box<dyn StorageTree>>>) |
| 41 | } |
| 42 | StorageType::Memory => { |
| 43 | use crate::storage::persistent::memory::MemoryStorageDriver; |
| 44 | let driver = MemoryStorageDriver::open(path)?; |
| 45 | Ok(Box::new(driver) as Box<dyn StorageDriver<Tree = Box<dyn StorageTree>>>) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | #[cfg(test)] |
| 51 | mod tests { |
no outgoing calls