Remove unnecessary trait bounds and pub funcs on RumorStore
* Remove unnecessary trait bound `Clone` for `T` on RumorStore
* Reduce public API on RumorStore by moving unnecessary public
functions to private functions
@@ -83,7 +83,7 @@ pub trait Rumor: Serialize {
fn write_to_bytes(&self) -> Result<Vec<u8>>;
}
-impl<'a, T: Rumor + Clone> From<&'a T> for RumorKey {
+impl<'a, T: Rumor> From<&'a T> for RumorKey {
fn from(rumor: &'a T) -> RumorKey {
RumorKey::new(rumor.kind(), rumor.id(), rumor.key())
}
@@ -99,7 +99,7 @@ pub struct RumorStore<T: Rumor> {
update_counter: Arc<AtomicUsize>,
}
-impl<T: Rumor + Clone> Default for RumorStore<T> {
+impl<T: Rumor> Default for RumorStore<T> {
fn default() -> RumorStore<T> {
RumorStore {
list: Arc::new(RwLock::new(HashMap::new())),
@@ -122,31 +122,18 @@ impl<T: Rumor> Serialize for RumorStore<T> {
{
let mut strukt = try!(serializer.serialize_struct("rumor_store", 2));
try!(strukt.serialize_field("list", &*(self.list.read().unwrap())));
- try!(strukt.serialize_field("update_counter",
- &self.update_counter.load(Ordering::Relaxed)));
+ try!(strukt.serialize_field("update_counter", &self.get_update_counter()));
strukt.end()
}
}
-impl<T: Rumor + Clone> RumorStore<T> {
+impl<T: Rumor> RumorStore<T> {
/// Create a new RumorStore for the given type. Allows you to initialize the counter to a
/// pre-set value. Useful mainly in testing.
pub fn new(counter: usize) -> RumorStore<T> {
RumorStore { update_counter: Arc::new(AtomicUsize::new(counter)), ..Default::default() }
}
- /// Increment the update counter for this store.
- ///
- /// We don't care if this repeats - it just needs to be unique for any given two states, which
- /// it will be.
- pub fn increment_update_counter(&self) {
- self.update_counter.fetch_add(1, Ordering::Relaxed);
- }
-
- pub fn get_update_counter(&self) -> usize {
- self.update_counter.load(Ordering::Relaxed)
- }
-
pub fn len_for_key(&self, key: &str) -> usize {
let list = self.list.read().expect("Rumor store lock poisoned");
list.get(key).map_or(0, |r| r.len())
@@ -218,6 +205,18 @@ impl<T: Rumor + Clone> RumorStore<T> {
None => false,
}
}
+
+ fn get_update_counter(&self) -> usize {
+ self.update_counter.load(Ordering::Relaxed)
+ }
+
+ /// Increment the update counter for this store.
+ ///
+ /// We don't care if this repeats - it just needs to be unique for any given two states, which
+ /// it will be.
+ fn increment_update_counter(&self) {
+ self.update_counter.fetch_add(1, Ordering::Relaxed);
+ }
}
/// The number of times a rumor will be shared before it goes cold for that member.
