diff --git a/examples/iterator.rs b/examples/iterator.rs index 5a29b31e..c149c580 100644 --- a/examples/iterator.rs +++ b/examples/iterator.rs @@ -25,8 +25,7 @@ fn main() { fs::create_dir_all(root.path()).unwrap(); let p = root.path(); - let created_arc = Manager::singleton().write().unwrap().get_or_create(p, Rkv::new).unwrap(); - let k = created_arc.read().unwrap(); + let k = Manager::singleton().write().unwrap().get_or_create(p, Rkv::new).unwrap(); let store = k.open_single("store", StoreOptions::create()).unwrap(); populate_store(&k, store).unwrap(); diff --git a/examples/simple-store.rs b/examples/simple-store.rs index 292cfa30..091b5259 100644 --- a/examples/simple-store.rs +++ b/examples/simple-store.rs @@ -53,8 +53,7 @@ fn main() { let p = root.path(); // The manager enforces that each process opens the same lmdb environment at most once - let created_arc = Manager::singleton().write().unwrap().get_or_create(p, Rkv::new).unwrap(); - let k = created_arc.read().unwrap(); + let k = Manager::singleton().write().unwrap().get_or_create(p, Rkv::new).unwrap(); // Creates a store called "store" let store = k.open_single("store", StoreOptions::create()).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 7a675442..482815f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,8 +60,7 @@ //! // at most once by caching a handle to each environment that it opens. //! // Use it to retrieve the handle to an opened environment—or create one //! // if it hasn't already been opened: -//! let created_arc = Manager::singleton().write().unwrap().get_or_create(path, Rkv::new).unwrap(); -//! let env = created_arc.read().unwrap(); +//! let env = Manager::singleton().write().unwrap().get_or_create(path, Rkv::new).unwrap(); //! //! // Then you can use the environment handle to get a handle to a datastore: //! let store: SingleStore = env.open_single("mydb", StoreOptions::create()).unwrap(); diff --git a/src/manager.rs b/src/manager.rs index c51564c8..01ad5188 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -58,7 +58,7 @@ where } pub struct Manager { - environments: BTreeMap>>, + environments: BTreeMap>, } impl Manager { @@ -73,7 +73,7 @@ impl Manager { } /// Return the open env at `path`, returning `None` if it has not already been opened. - pub fn get<'p, P>(&self, path: P) -> Result>>, ::std::io::Error> + pub fn get<'p, P>(&self, path: P) -> Result>, ::std::io::Error> where P: Into<&'p Path>, { @@ -82,7 +82,7 @@ impl Manager { } /// Return the open env at `path`, or create it by calling `f`. - pub fn get_or_create<'p, F, P>(&mut self, path: P, f: F) -> Result>, StoreError> + pub fn get_or_create<'p, F, P>(&mut self, path: P, f: F) -> Result, StoreError> where F: FnOnce(&Path) -> Result, P: Into<&'p Path>, @@ -91,7 +91,7 @@ impl Manager { Ok(match self.environments.entry(canonical) { Entry::Occupied(e) => e.get().clone(), Entry::Vacant(e) => { - let k = Arc::new(RwLock::new(f(e.key().as_path())?)); + let k = Arc::new(f(e.key().as_path())?); e.insert(k).clone() }, }) @@ -104,7 +104,7 @@ impl Manager { path: P, capacity: c_uint, f: F, - ) -> Result>, StoreError> + ) -> Result, StoreError> where F: FnOnce(&Path, c_uint) -> Result, P: Into<&'p Path>, @@ -113,7 +113,7 @@ impl Manager { Ok(match self.environments.entry(canonical) { Entry::Occupied(e) => e.get().clone(), Entry::Vacant(e) => { - let k = Arc::new(RwLock::new(f(e.key().as_path(), capacity)?)); + let k = Arc::new(f(e.key().as_path(), capacity)?); e.insert(k).clone() }, })