summaryrefslogtreecommitdiffstats
path: root/libimagcounter
diff options
context:
space:
mode:
Diffstat (limited to 'libimagcounter')
-rw-r--r--libimagcounter/src/counter.rs20
-rw-r--r--libimagcounter/src/error.rs1
-rw-r--r--libimagcounter/src/lib.rs2
3 files changed, 15 insertions, 8 deletions
diff --git a/libimagcounter/src/counter.rs b/libimagcounter/src/counter.rs
index 8aa7e4bb..e6a6e309 100644
--- a/libimagcounter/src/counter.rs
+++ b/libimagcounter/src/counter.rs
@@ -48,8 +48,10 @@ impl<'a> Counter<'a> {
debug!("Creating new counter: '{}' with value: {}", name, init);
let fle = {
- let mut lockentry = try!(store.create(ModuleEntryPath::new(name.clone()).into_storeid())
- .map_err_into(CEK::StoreWriteError));
+ let id = try!(ModuleEntryPath::new(name.clone())
+ .into_storeid()
+ .map_err_into(CEK::StoreWriteError));
+ let mut lockentry = try!(store.create(id).map_err_into(CEK::StoreWriteError));
{
let mut entry = lockentry.deref_mut();
@@ -153,7 +155,7 @@ impl<'a> Counter<'a> {
})
}
- fn read_header_at<T, F>(&self, name: &str, f: F) -> Result<T>
+ fn read_header_at<T, F>(&self, name: &str, f: F) -> Result<T>
where F: FnOnce(Option<Value>) -> Result<T>
{
self.fle.get_header().read(name).map_err_into(CEK::StoreWriteError).and_then(f)
@@ -161,14 +163,18 @@ impl<'a> Counter<'a> {
pub fn load(name: CounterName, store: &Store) -> Result<Counter> {
debug!("Loading counter: '{}'", name);
- let id = ModuleEntryPath::new(name).into_storeid();
+ let id = try!(ModuleEntryPath::new(name)
+ .into_storeid()
+ .map_err_into(CEK::StoreWriteError));
Counter::from_storeid(store, id)
}
pub fn delete(name: CounterName, store: &Store) -> Result<()> {
debug!("Deleting counter: '{}'", name);
- store.delete(ModuleEntryPath::new(name).into_storeid())
- .map_err_into(CEK::StoreWriteError)
+ let id = try!(ModuleEntryPath::new(name)
+ .into_storeid()
+ .map_err_into(CEK::StoreWriteError));
+ store.delete(id).map_err_into(CEK::StoreWriteError)
}
pub fn all_counters(store: &Store) -> Result<CounterIterator> {
@@ -195,7 +201,7 @@ impl<'a> FromStoreId for Counter<'a> {
.map_err_into(CEK::StoreReadError)
.and_then(|u| {
counter.unit = u;
- Ok(counter)
+ Ok(counter)
})
}
}
diff --git a/libimagcounter/src/error.rs b/libimagcounter/src/error.rs
index e8016fb6..e151c407 100644
--- a/libimagcounter/src/error.rs
+++ b/libimagcounter/src/error.rs
@@ -1,5 +1,6 @@
generate_error_module!(
generate_error_types!(CounterError, CounterErrorKind,
+ StoreIdError => "StoreId error",
StoreReadError => "Store read error",
StoreWriteError => "Store write error",
HeaderTypeError => "Header type error",
diff --git a/libimagcounter/src/lib.rs b/libimagcounter/src/lib.rs
index 957ac9f9..75340ad6 100644
--- a/libimagcounter/src/lib.rs
+++ b/libimagcounter/src/lib.rs
@@ -19,7 +19,7 @@ extern crate toml;
#[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror;
-module_entry_path_mod!("counter", "0.2.0");
+module_entry_path_mod!("counter");
pub mod counter;
pub mod error;