Use Self:: where possible
- Id
- 0ed8abb97a9156ce350d5774d9dedbcb4892a18d
- Author
- Caio
- Commit time
- 2025-12-13T09:53:25+01:00
Modified src/error.rs
match (self, other) {
// Wrapped errors have to allocate to compare :(
// But PartialEq on an error type is mostly useful for tests
- (Error::Encode(a), Error::Encode(b)) => a.to_string().eq(&b.to_string()),
- (Error::Decode(a), Error::Decode(b)) => a.to_string().eq(&b.to_string()),
- (Error::CustomBroadcast(a), Error::CustomBroadcast(b)) => {
+ (Self::Encode(a), Self::Encode(b)) => a.to_string().eq(&b.to_string()),
+ (Self::Decode(a), Self::Decode(b)) => a.to_string().eq(&b.to_string()),
+ (Self::CustomBroadcast(a), Self::CustomBroadcast(b)) => {
a.to_string().eq(&b.to_string())
}
- (Error::DataTooBig, Error::DataTooBig) => true,
- (Error::NotConnected, Error::NotConnected) => true,
- (Error::NotUndead, Error::NotUndead) => true,
- (Error::SameIdentity, Error::SameIdentity) => true,
- (Error::IncompleteProbeCycle, Error::IncompleteProbeCycle) => true,
- (Error::DataFromOurselves, Error::DataFromOurselves) => true,
- (Error::IndirectForOurselves, Error::IndirectForOurselves) => true,
- (Error::MalformedPacket, Error::MalformedPacket) => true,
- (Error::InvalidConfig, Error::InvalidConfig) => true,
+ (Self::DataTooBig, Self::DataTooBig) => true,
+ (Self::NotConnected, Self::NotConnected) => true,
+ (Self::NotUndead, Self::NotUndead) => true,
+ (Self::SameIdentity, Self::SameIdentity) => true,
+ (Self::IncompleteProbeCycle, Self::IncompleteProbeCycle) => true,
+ (Self::DataFromOurselves, Self::DataFromOurselves) => true,
+ (Self::IndirectForOurselves, Self::IndirectForOurselves) => true,
+ (Self::MalformedPacket, Self::MalformedPacket) => true,
+ (Self::InvalidConfig, Self::InvalidConfig) => true,
// Instead of a catch-all here, we explicitly enumerate our variants
// so that when/if new errors are added we don't silently introduce
// a bug
- (Error::Encode(_), _) => false,
- (Error::Decode(_), _) => false,
- (Error::CustomBroadcast(_), _) => false,
- (Error::DataTooBig, _) => false,
- (Error::NotConnected, _) => false,
- (Error::NotUndead, _) => false,
- (Error::SameIdentity, _) => false,
- (Error::IncompleteProbeCycle, _) => false,
- (Error::DataFromOurselves, _) => false,
- (Error::IndirectForOurselves, _) => false,
- (Error::MalformedPacket, _) => false,
- (Error::InvalidConfig, _) => false,
+ (Self::Encode(_), _) => false,
+ (Self::Decode(_), _) => false,
+ (Self::CustomBroadcast(_), _) => false,
+ (Self::DataTooBig, _) => false,
+ (Self::NotConnected, _) => false,
+ (Self::NotUndead, _) => false,
+ (Self::SameIdentity, _) => false,
+ (Self::IncompleteProbeCycle, _) => false,
+ (Self::DataFromOurselves, _) => false,
+ (Self::IndirectForOurselves, _) => false,
+ (Self::MalformedPacket, _) => false,
+ (Self::InvalidConfig, _) => false,
}
}
}
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
#[allow(clippy::match_same_arms)]
match self {
- Error::DataTooBig => {
+ Self::DataTooBig => {
formatter.write_str("Received data larger than maximum configured limit")
}
- Error::NotUndead => formatter.write_str("Useless attempt to reuse a functioning Foca"),
- Error::SameIdentity => {
+ Self::NotUndead => formatter.write_str("Useless attempt to reuse a functioning Foca"),
+ Self::SameIdentity => {
formatter.write_str("New identity is the same as the current one")
}
- Error::NotConnected => formatter.write_str("BUG! Expected to be connected, but wasn't"),
- Error::IncompleteProbeCycle => {
+ Self::NotConnected => formatter.write_str("BUG! Expected to be connected, but wasn't"),
+ Self::IncompleteProbeCycle => {
formatter.write_str("BUG! Probe cycle finished without running its full course")
}
- Error::DataFromOurselves => formatter.write_str(concat!(
+ Self::DataFromOurselves => formatter.write_str(concat!(
"Received data from something claiming to have ",
"an identity equal to our own"
)),
- Error::IndirectForOurselves => formatter.write_str(concat!(
+ Self::IndirectForOurselves => formatter.write_str(concat!(
"Received message that was supposed to reach us only ",
"via indirect means"
)),
- Error::MalformedPacket => formatter.write_str("Payload with more data than expected"),
- Error::Encode(err) => err.fmt(formatter),
- Error::Decode(err) => err.fmt(formatter),
- Error::CustomBroadcast(err) => err.fmt(formatter),
- Error::InvalidConfig => formatter.write_str("Invalid configuration"),
+ Self::MalformedPacket => formatter.write_str("Payload with more data than expected"),
+ Self::Encode(err) => err.fmt(formatter),
+ Self::Decode(err) => err.fmt(formatter),
+ Self::CustomBroadcast(err) => err.fmt(formatter),
+ Self::InvalidConfig => formatter.write_str("Invalid configuration"),
}
}
}
Modified src/payload.rs
impl<T> Message<T> {
pub(crate) const fn allow_custom_broadcasts(&self) -> bool {
- !matches!(self, Message::Announce | Message::TurnUndead)
+ !matches!(self, Self::Announce | Self::TurnUndead)
}
pub(crate) const fn needs_piggyback(&self) -> bool {
- !matches!(
- self,
- Message::Announce | Message::TurnUndead | Message::Broadcast
- )
+ !matches!(self, Self::Announce | Self::TurnUndead | Self::Broadcast)
}
pub(crate) const fn piggyback_only_active(&self) -> bool {
- matches!(self, Message::Feed)
+ matches!(self, Self::Feed)
}
}
Modified src/runtime.rs
impl<T> Timer<T> {
const fn seq(&self) -> u8 {
match self {
- Timer::SendIndirectProbe {
+ Self::SendIndirectProbe {
probed_id: _,
token: _,
} => 0,
- Timer::ProbeRandomMember(_) => 1,
- Timer::ChangeSuspectToDown {
+ Self::ProbeRandomMember(_) => 1,
+ Self::ChangeSuspectToDown {
member_id: _,
incarnation: _,
token: _,
} => 2,
- Timer::PeriodicAnnounce(_) => 3,
- Timer::PeriodicGossip(_) => 4,
- Timer::RemoveDown(_) => 5,
- Timer::PeriodicAnnounceDown(_) => 6,
+ Self::PeriodicAnnounce(_) => 3,
+ Self::PeriodicGossip(_) => 4,
+ Self::RemoveDown(_) => 5,
+ Self::PeriodicAnnounceDown(_) => 6,
}
}
}