config : RwLock<Arc<ServerConfig>>,
dirty : Mutex<VecDeque<InstanceRef>>,
save_area_lock : Mutex<Option<File>>,
- pub shapelibs : RwLock<HashMap<String,shapelib::Contents>>,
+ pub shapelibs : RwLock<shapelib::Registry>,
}
#[derive(Debug)]
pub use std::fmt::{self,Display,Debug};
pub use std::thread;
pub use std::time::Duration;
-pub use std::sync::{Arc,Mutex,MutexGuard,RwLock,Condvar};
+pub use std::sync::{Arc,Mutex,MutexGuard,RwLock,RwLockReadGuard,Condvar};
pub use std::collections::{HashMap,hash_map,HashSet};
pub use std::borrow::Borrow;
pub use std::convert::{TryFrom,TryInto};
// Item } once loaded and part of a game,
// Outline } no Arc's as we serialise/deserialize during save/load
+pub type Registry = HashMap<String,shapelib::Contents>;
+
#[derive(Debug)]
pub struct Contents {
libname: String,
fn itemname(&self) -> &str { &self.itemname }
}
+use rental::common::RentRef;
+
+#[throws(SpecError)]
+pub fn libs_lookup(libname: &str) -> RentRef<RwLockReadGuard<'static, Registry>, Contents> {
+ let libs = GLOBAL.shapelibs.read().unwrap();
+ RentRef::try_new(libs,|libs|Ok({
+ libs.get(libname).ok_or(SE::LibraryNotFound)?
+ })).map_err::<SpecError,_>(|e:rental::RentalError<_,_>|e.0)?
+}
+
impl ItemSpec {
#[throws(SpecError)]
pub fn load(&self) -> Box<dyn Piece> {
- let libs = GLOBAL.shapelibs.read().unwrap();
- let lib = libs.get(&self.lib).ok_or(SE::LibraryNotFound)?;
+ let lib = libs_lookup(&self.lib)?;
let idata = lib.items.get(&self.item).ok_or(SE::LibraryItemNotFound)?;
lib.load1(idata, &self.item)?
}