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 libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error_exit; use libimagerror::trace::trace_error_exit;
use libimagcounter::counter::Counter; use libimagcounter::counter::Counter;
use libimagcounter::counter::CounterUnit;
pub fn create(rt: &Runtime) { pub fn create(rt: &Runtime) {
rt.cli() rt.cli()
@ -19,7 +20,7 @@ pub fn create(rt: &Runtime) {
.value_of("unit") .value_of("unit")
.unwrap_or("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) => { Err(e) => {
warn!("Could not create Counter '{}' with initial value '{} {}'", name, init, unit); warn!("Could not create Counter '{}' with initial value '{} {}'", name, init, unit);
trace_error_exit(&e, 1); trace_error_exit(&e, 1);

View file

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