From aeb27072a7458dfa046763b96a06124eda059413 Mon Sep 17 00:00:00 2001 From: Kai Sickeler Date: Sun, 17 Jul 2016 16:26:11 +0200 Subject: [PATCH] use CounterUnit::new instead of a pub member --- imag-counter/src/create.rs | 2 +- libimagcounter/src/counter.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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>, }