Update toml-query: 0.2.0 -> 0.3.0

This commit is contained in:
Matthias Beyer 2017-07-09 21:48:01 +02:00
parent 19e8be9f9b
commit bddc79efaa
2 changed files with 13 additions and 10 deletions

View file

@ -16,7 +16,7 @@ homepage = "http://imag-pim.org"
[dependencies] [dependencies]
log = "0.3" log = "0.3"
toml = "0.4.*" toml = "0.4.*"
toml-query = "0.2.*" toml-query = "0.3.*"
semver = "0.5" semver = "0.5"
[dependencies.libimagstore] [dependencies.libimagstore]

View file

@ -117,7 +117,7 @@ impl<'a> Counter<'a> {
let mut header = self.fle.deref_mut().get_header_mut(); let mut header = self.fle.deref_mut().get_header_mut();
let query = String::from("counter.value"); let query = String::from("counter.value");
match try!(header.read(&query).map_err_into(CEK::StoreReadError)) { match try!(header.read(&query).map_err_into(CEK::StoreReadError)) {
&Value::Integer(i) => { Some(&Value::Integer(i)) => {
header.set(&query, Value::Integer(i + 1)) header.set(&query, Value::Integer(i + 1))
.map_err_into(CEK::StoreWriteError) .map_err_into(CEK::StoreWriteError)
.map(|_| ()) .map(|_| ())
@ -130,7 +130,7 @@ impl<'a> Counter<'a> {
let mut header = self.fle.deref_mut().get_header_mut(); let mut header = self.fle.deref_mut().get_header_mut();
let query = String::from("counter.value"); let query = String::from("counter.value");
match try!(header.read(&query).map_err_into(CEK::StoreReadError)) { match try!(header.read(&query).map_err_into(CEK::StoreReadError)) {
&Value::Integer(i) => { Some(&Value::Integer(i)) => {
header.set(&query, Value::Integer(i - 1)) header.set(&query, Value::Integer(i - 1))
.map_err_into(CEK::StoreWriteError) .map_err_into(CEK::StoreWriteError)
.map(|_| ()) .map(|_| ())
@ -152,15 +152,17 @@ impl<'a> Counter<'a> {
pub fn name(&self) -> Result<CounterName> { pub fn name(&self) -> Result<CounterName> {
self.read_header_at("counter.name", |v| match v { self.read_header_at("counter.name", |v| match v {
&Value::String(ref s) => Ok(s.clone()), Some(&Value::String(ref s)) => Ok(s.clone()),
_ => Err(CEK::HeaderTypeError.into_error()), Some(_) => Err(CEK::HeaderTypeError.into_error()),
_ => Err(CEK::StoreReadError.into_error()),
}) })
} }
pub fn value(&self) -> Result<i64> { pub fn value(&self) -> Result<i64> {
self.read_header_at("counter.value", |v| match v { self.read_header_at("counter.value", |v| match v {
&Value::Integer(i) => Ok(i), Some(&Value::Integer(i)) => Ok(i),
_ => Err(CEK::HeaderTypeError.into_error()), Some(_) => Err(CEK::HeaderTypeError.into_error()),
_ => Err(CEK::StoreReadError.into_error()),
}) })
} }
@ -170,13 +172,14 @@ impl<'a> Counter<'a> {
pub fn read_unit(&self) -> Result<Option<CounterUnit>> { pub fn read_unit(&self) -> Result<Option<CounterUnit>> {
self.read_header_at("counter.unit", |s| match s { self.read_header_at("counter.unit", |s| match s {
&Value::String(ref s) => Ok(Some(CounterUnit::new(s.clone()))), Some(&Value::String(ref s)) => Ok(Some(CounterUnit::new(s.clone()))),
_ => Err(CEK::HeaderTypeError.into_error()), Some(_) => Err(CEK::HeaderTypeError.into_error()),
_ => Err(CEK::StoreReadError.into_error()),
}) })
} }
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(&Value) -> Result<T> where F: FnOnce(Option<&Value>) -> Result<T>
{ {
self.fle self.fle