changed Unit-String to CounterUnit-Type

This commit is contained in:
Kai Sickeler 2016-07-16 20:44:50 +02:00
parent cd182c73f4
commit 7e4166acbf
2 changed files with 6 additions and 7 deletions

View file

@ -3,6 +3,7 @@ use std::str::FromStr;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error_exit;
use libimagcounter::counter::Counter;
use libimagcounter::counter::CounterUnit;
pub fn create(rt: &Runtime) {
rt.cli()
@ -19,7 +20,7 @@ pub fn create(rt: &Runtime) {
.value_of("unit")
.unwrap_or("unit");
match Counter::new(rt.store(), String::from(name), init, String::from(unit)) {
match Counter::new(rt.store(), String::from(name), init, CounterUnit(String::from(unit))) {
Err(e) => {
warn!("Could not create Counter '{}' with initial value '{} {}'", name, init, unit);
trace_error_exit(&e, 1);

View file

@ -137,12 +137,10 @@ impl<'a> Counter<'a> {
pub fn unit(&self) -> Result<CounterUnit> {
self.fle.get_header().read("counter.unit")
.map_err(|e| CEK::StoreWriteError.into_error_with_cause(Box::new(e)))
.and_then(|u|
match u {
Some(Value::String(s)) => Ok(CounterUnit(s)),
_ => Err(CEK::HeaderTypeError.into_error())
}
)
.and_then(|u| match u {
Some(Value::String(s)) => Ok(CounterUnit(s)),
_ => Err(CEK::HeaderTypeError.into_error())
})
}
pub fn load(name: CounterName, store: &Store) -> Result<Counter> {