diff --git a/imag-counter/src/create.rs b/imag-counter/src/create.rs index 96b58b54..dab5e972 100644 --- a/imag-counter/src/create.rs +++ b/imag-counter/src/create.rs @@ -20,7 +20,7 @@ pub fn create(rt: &Runtime) { .value_of("unit") .unwrap_or("unit"); - match Counter::new(rt.store(), String::from(name), init, CounterUnit(String::from(unit))) { + match Counter::new(rt.store(), String::from(name), init, CounterUnit::new(unit)) { Err(e) => { warn!("Could not create Counter '{}' with initial value '{} {}'", name, init, unit); trace_error_exit(&e, 1); diff --git a/libimagcounter/src/counter.rs b/libimagcounter/src/counter.rs index f0ccc217..baba38a4 100644 --- a/libimagcounter/src/counter.rs +++ b/libimagcounter/src/counter.rs @@ -21,7 +21,7 @@ use error::CounterErrorKind as CEK; pub type CounterName = String; #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] -pub struct CounterUnit(pub String); +pub struct CounterUnit(String); impl Display for CounterUnit { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -29,6 +29,12 @@ impl Display for CounterUnit { } } +impl CounterUnit { + pub fn new>(unit: S) -> CounterUnit { + CounterUnit(unit.into()) + } +} + pub struct Counter<'a> { fle: FileLockEntry<'a>, }