MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / create_storage_driver

Function create_storage_driver

graphlite/src/storage/persistent/factory.rs:32–48  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

30/// let tree = driver.open_tree("my_tree")?;
31/// ```
32pub 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)]
51mod tests {

Callers 2

init_disk_onlyMethod · 0.85
test_create_sled_driverFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_create_sled_driverFunction · 0.68