From 68ee18e4e89736ab70f0933c0a4c5d60fa13803d Mon Sep 17 00:00:00 2001 From: Dru Sellers Date: Thu, 3 May 2018 02:07:46 -0500 Subject: [PATCH] Add Index::open_directory function (#285) * Add Index::open_directory function * dry --- src/core/index.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/index.rs b/src/core/index.rs index 4d822ced2..8ad0a5098 100644 --- a/src/core/index.rs +++ b/src/core/index.rs @@ -103,10 +103,10 @@ impl Index { Ok(index) } - /// Create a new index from a directory. - pub fn from_directory(mut directory: ManagedDirectory, schema: Schema) -> Result { - save_new_metas(schema.clone(), 0, directory.borrow_mut())?; - let metas = IndexMeta::with_schema(schema); + /// Open the index using the provided directory + pub fn open_directory(directory: D) -> Result { + let directory = ManagedDirectory::new(directory)?; + let metas = load_metas(&directory)?; Index::create_from_metas(directory, &metas) } @@ -114,8 +114,13 @@ impl Index { #[cfg(feature = "mmap")] pub fn open>(directory_path: P) -> Result { let mmap_directory = MmapDirectory::open(directory_path)?; - let directory = ManagedDirectory::new(mmap_directory)?; - let metas = load_metas(&directory)?; + Index::open_directory(mmap_directory) + } + + /// Create a new index from a directory. + pub fn from_directory(mut directory: ManagedDirectory, schema: Schema) -> Result { + save_new_metas(schema.clone(), 0, directory.borrow_mut())?; + let metas = IndexMeta::with_schema(schema); Index::create_from_metas(directory, &metas) }