PR feedback: Implement ElectionRumor more simply
@@ -30,22 +30,12 @@ pub use protocol::newscast::{election::Status as ElectionStatus, Election as Pro
use protocol::{self, newscast, FromProto};
use rumor::{Rumor, RumorPayload, RumorType};
-// The default implementations leverage ElectionUpdate's Deref -> Election behavior, but this
-// generates a warning. In practice, it's fine:
-// See https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=162d64d74390df6a3a8bb815cd3a2c73
-#[allow(unconditional_recursion)]
pub trait ElectionRumor {
- fn member_id(&self) -> &str {
- self.member_id()
- }
+ fn member_id(&self) -> &str;
- fn is_finished(&self) -> bool {
- self.is_finished()
- }
+ fn is_finished(&self) -> bool;
- fn term(&self) -> u64 {
- self.term()
- }
+ fn term(&self) -> u64;
}
#[derive(Debug, Clone, Serialize)]
@@ -242,7 +232,19 @@ impl ElectionUpdate {
}
}
-impl ElectionRumor for ElectionUpdate {}
+impl ElectionRumor for ElectionUpdate {
+ fn member_id(&self) -> &str {
+ &self.member_id
+ }
+
+ fn is_finished(&self) -> bool {
+ self.status == ElectionStatus::Finished
+ }
+
+ fn term(&self) -> u64 {
+ self.term
+ }
+}
impl Deref for ElectionUpdate {
type Target = Election;
